ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

changing text to "title" format

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • changing text to "title" format

    Title case a string - Procedure
    Just a small example...you can modifiy
    as you see fit.


    Code:
    crtsrcpf qtemp/source rcdlen(112)
    Place the three source members in there.

    compile the procedure TITLE first...
    Code:
    CRTRPGMOD MODULE(QTEMP/TITLE) SRCFILE(qtemp/Source)
    TITLE:
    Code:
         H NOMAIN EXPROPTS(*RESDECPOS)
    
          * PROGRAM - Title
          * PURPOSE - Subprocedure to format text string as a title
          * WRITTEN - 01/17/05
          * AUTHOR  - 
    
          * Parameters
          *       AfterString           Char 256   Output
          *       BeforeString          Char 256   Input
    
          * Indicator Usage
          *   None
    
          *   The TITLE_CP copy member should be used by programs that call this subprocedure
          *   to obtain the procedure prototype fields.
    
          /copy source,TITLE_CP
    
         d BeforeString    s            256
         d Count           s              4  0
         d CurrentOne      s              1
         d LastOne         s              1
          *
         d Up              c                   CONST('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
         d Lo              c                   CONST('abcdefghijklmnopqrstuvwxyz')
          *
    
          * Begin Procedure
         P Title           B                   export
    
          * Procedure Interface
         d Title           pi           256
         d AfterString                  256    value
    
          * After below line of code is processed
          * BeforeString = my name is jimmyoctane
          * AfterString =  My Name Is Jimmyoctane
          *
    
          /free
    
               clear AfterString;
             //
             //  Lower case the entire thing
             //
               BeforeString = %Xlate(Up:Lo:BeforeString);
    
               for count = 1 to %len(%trim(BeforeString));
                CurrentOne = %subst(BeforeString:count:1);
    
                select;
                 when count = 1;
                  AfterString = %Trim(%Xlate(Lo:Up:%Subst(BeforeString:1:1)));
    
                 when %subst(BeforeString:count:4) = 'mfg ' or
                      %subst(BeforeString:count:4) = 'inc ' or
                      %subst(BeforeString:count:4) = 'inc.' or
                      %subst(BeforeString:count:4) = 'ind ' or
                      %subst(BeforeString:count:4) = 'co. ' or
                      %subst(BeforeString:count:4) = 'co  ' or
                      %subst(BeforeString:count:4) = 'llc.' or
                      %subst(BeforeString:count:4) = 'llc ' ;
    
                  %subst(AfterString:count:3)= %Trim(%Xlate(Lo:Up:%Subst(
                  BeforeString:count:3)));
                  count +=2;
                  iter;
    
                 when LastOne = *blanks or
                      LastOne = '-'     or
                      LastOne = '.'     or
                      LastOne = '/';
                  AfterString = %Subst(AfterString:1:count-1) +
                                %Trim(%Xlate(Lo:Up:%Subst(
                                BeforeString:count:1)) +
                                %Subst(AfterString:count+1));
                 other;
                  %subst(AfterString:count:1) =
                  %subst(BeforeString:count:1);
                 endsl;
    
                 LastOne = %subst(BeforeString:count:1);
                endfor;
    
                return    AfterString;
    
          /end-free
         p Title           E





    then the testing program its named TITLETEST

    Code:
    CRTRPGMOD MODULE(QTEMP/TITLETST) SRCFILE(qtemp/Source)
    Then
    Code:
    crtpgm qtemp/titletst  module(titletest  title)
    now call titletst (as easy as calling an SQL function)
    but maybe a bit easier to tweak.

    Code:
     /copy source,TITLE_CP                                                           
    d Test            s             28                                               
    d reply           s              1                                               
     *                                                                               
    c                   eval      Test =  TITLE('My very ENERGETIC MoTher')          
    c     Test          dsply                   reply                                
    c                   eval      Test =  TITLE('AS400Pro Smells lIKE DOG')          
    c     Test          dsply                   reply                                
    c                   eval      Test =  TITLE('1722 ShARON Road StREATOR')         
    c     Test          dsply                   reply                                
    c                   eval      *inlr = *on
    Attached Files
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com
Working...
X