Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Use RPG String Manipulation Built-In Functions to Remove Spaces

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

  • Use RPG String Manipulation Built-In Functions to Remove Spaces

    ** This thread discusses the article: Use RPG String Manipulation Built-In Functions to Remove Spaces **
    ** This thread discusses the Content article: Use RPG String Manipulation Built-In Functions to Remove Spaces **
    I used to use %replace to remove the whitespace from a string (code below), but I am going to go back and tweak the service program to use %subst to increase its efficiency.


    d whitespace pr a varying len(4193271)
    d text a varying const len(4193271)

    p whitespace b export
    d whitespace pi a varying len(4193271)
    d textin a varying const len(4193271)
    d textout s a varying len(4193271)
    d done s n inz(*off)

    /free
    textout = %triml(textin);
    dou done;
    monitor;
    textout = %replace(:textout:%scan(:%trimr(textout)):2);
    on-error *all;
    done = *on;
    endmon;
    enddo;
    return textout;
    /end-free

    p whitespace e


    switching to %scan and %trim like in the article made the procedure over 3 times faster


    d whitespace pr a varying len(4193271)
    d text a varying const len(4193271)

    p whitespace b export
    d whitespace pi a varying len(4193271)
    d textin a varying const len(4193271)
    d textout s a varying len(4193271) inz()
    d done s n inz(*off)
    d position s 10u 0 inz(0)

    /free
    textout = %triml(textin);
    dou done;
    position = %scan(:%trimr(textout): position + 1);
    if position = 0;
    leave;
    endif;
    textout = %subst(textout:1: position)
    + %triml(%subst(textout: position));
    enddo;
    return textout;
    /end-free

    p whitespace e
    Last edited by kketzler; 09-08-2009, 07:36 AM. Reason: new information
Working...
X