ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Delete spaces from a variable

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

  • Delete spaces from a variable

    Hello,

    I need to delete the spaces from a variable e.g.
    ?Special Care Assistant? needs to be saved as ?SpecialCareAssistant?. Can?t seem to get this to work after messing around with BIFs.

    Any ideas?

  • #2
    Re: Delete spaces from a variable

    look at the last example on this post the first parm of %replace = " ' ' "
    this cause the replace to remove



    Code:
     d fnd             s              3  0                                 
     d string          s             30    inz('Special Care Assistant')   
      *                                                                    
      *                                                                    
      /free                                                                
                                                                           
            dou fnd = %len(string);                                        
            fnd = %scan(' ' : string:fnd+1);                               
            STRING = %replace('' : string:fnd:1);                          
            enddo;                                                         
            dsply string ' ' ;                                             
                                                                           
           *inlr = *on;                                                    
                                                                           
      /end-free
    jamie
    Last edited by jamief; May 19, 2008, 11:26 AM. Reason: added code
    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

    Comment


    • #3
      Re: Delete spaces from a variable

      Works like a charm. Seems so easy now!
      Thanks!

      Comment


      • #4
        Re: Delete spaces from a variable

        Hi,

        the SQL scalar function REPLACE is much more powerfull, because it replaces ALL occurrences, instead of only the first one.

        To remove all *Blanks the following SQL-Statement can be used

        PHP Code:
        Exec SQL  Set :NewString REPLACE(TRIM(:OldString), ' '''); 
        Birgitta

        Comment


        • #5
          Re: Delete spaces from a variable

          Thank Birgitta.....once again you come thru!

          Take care and give a good-o-kick to Kit if you run into him again.
          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

          Comment

          Working...
          X