ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%Replace

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

  • %Replace

    I have a 16 digit GL account# that I want to remove the dash from and poulate into another field. How to do this with %replace

  • #2
    Re: %Replace

    444-555-6769898909
    do you want 4445556769898909
    or 444 555 6769898909 ?
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: %Replace

      Originally posted by DeadManWalks View Post
      444-555-6769898909
      do you want 4445556769898909
      or 444 555 6769898909 ?
      4445556769.....

      no spaces

      Comment


      • #4
        Re: %Replace

        I found this code that Birgitta provided that works pretty well

        Text50 = 'XXX-YYY-ZZZ-123-456-789';
        DoW %Scan('-': Text50) > *Zeros;
        Text50 = %Replace('' : Text50: %Scan('-': Text50): 1)
        EndDo;

        Comment


        • #5
          Re: %Replace

          Put an empty string in the first parm of %replace. Put a 1 in the fourth parm.

          Code:
          D Account         s             16a                                
          D EditedAccount   s             16a                                
          D Pos             s              5i 0                              
          D EmptyString     c                    const('')                   
           /free                                                                                                          
               EditedAccount = Account;                                      
               dow '1';                                                      
                  Pos = %scan('-': EditedAccount);                           
                  if (Pos <= *zero);                                         
                     leave;                                                  
                  endif;                                                     
                  EditedAccount = %replace(EmptyString: EditedAccount:Pos:1);
               enddo;
          This may help:

          http://www.itjungle.com/fhg/fhg042507-story02.html

          Comment


          • #6
            Re: %Replace

            I know you said %replace, but if you're on i7.1, then you can use the new %scanrpl and do it very simply.

            Comment


            • #7
              Re: %Replace

              Hi,

              Code:
              d i               s             10i 0   
              d acc             s             15a     
              d accnew          s             15a     
               /free     
                                           
               acc = '444-555-676989890';                   
               accnew = *blanks;                            
               for i = 1 to %len(acc);                      
                 if %subst(acc:i:1) >= '0';                 
                   accnew = %trim(accnew) + %subst(acc:i:1);
                 endif;                                     
               endfor;                                      
               dsply accnew;

              Comment


              • #8
                Re: %Replace

                Originally posted by Viking View Post
                I know you said %replace, but if you're on i7.1, then you can use the new %scanrpl and do it very simply.
                We have 7.1 but I am getting token not valid trying to use %scanrpl. I am using SEU, though, could it be SEU doesn't support it

                Comment


                • #9
                  Re: %Replace

                  SEU will not recognize it or any future enhancements to the language, but your compiler will compile it just fine. Go ahead and give it a try.

                  p.s. Another good reason to move to RDi!

                  Comment


                  • #10
                    Re: %Replace

                    Plus, if you get tired of SEU giving you strange errors, write a wrapper for %ScanRpl, call it ScanRpl, stick it in your 'utilities' service program, and SEU will stop pestering you. If you haven't got a 'utilities' service program, it's a good reason to get one written.

                    Comment

                    Working...
                    X