Focal Point
Removing Embedded spaces

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8021045341

December 14, 2005, 03:58 PM
dhofman
Removing Embedded spaces
I have an alphanumeric field that has spaces between significant digits that can occur any place within that field (ie. no set postion in the field). Is there a way to remove the embedded spaces, basically smashing everything together? I figured out how to remove them before or after significant digits, but not when they are in the middle.

Hopefully someone can help. Thanks
December 14, 2005, 04:34 PM
jimster06
In the Technical Documenation Library above, search for STRIP.


jimster06
DevStu WF 7.6.11
W7
HTML, PDF, EXL2K
December 14, 2005, 05:00 PM
smiths
Here's one method using SUBSTR. Loop through your string a character at a time, and build a new string based on the non-blank characters.

-* Set initial value to be parsed
-SET &FIELD = ' 12 3 xxx 456 7 8 9 ';

-* Get the length of the field
-SET &FIELD_LEN = &FIELD.LENGTH;

-* Set the field format
-SET &FIELD_FMT = 'A' | &FIELD_LEN;

-* Initialize the field that will store the parsed field
-SET &NEWSTR = '';

-* Initialize the loop index
-SET &IDX = 1;

-* Iterate through the number (&FIELD)
-REPEAT :ENDLOOP WHILE &IDX LE &FIELD_LEN;

-* Get the next character in the string
-SET &CHARACTER = SUBSTR(&FIELD_LEN, &FIELD, &IDX,
- &IDX, 1, 'A1');

-* If a non-blank is found, append it to the new
-* string, otherwise do nothing
-SET &NEWSTR = IF (&CHARACTER NE ' ') THEN &NEWSTR || &CHARACTER
-ELSE &NEWSTR;

-* Advance to the next character
-SET &IDX = &IDX + 1;

-:ENDLOOP

-* Remove trailing space
-SET &NEWSTR = TRUNCATE(&NEWSTR);

-* Here's the final value
-TYPE NEWSTR: (&NEWSTR)


------------------------------------------------------------------------
PROD: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
TEST: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
December 14, 2005, 06:59 PM
susannah
and SQUEEZ function will smash multiple blanks to a single blank, might be a good way to start.




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
December 14, 2005, 08:02 PM
Mikel
As jimster06 said, I think STRIP function is the right option.

TABLE FILE CAR
  PRINT
    COMPUTE TEST1/A15   = ' 1 2 3 5. 6   5' ;
    COMPUTE TEST2/A15   = STRIP(15, TEST1, ' ', TEST2);
    COMPUTE TEST3/D15.2 = ATODBL(TEST2, '15', TEST3); 
    COUNTRY
  IF READLIMIT EQ 1
END
-RUN


Regards,
Mikel


WebFOCUS 8.1.05, 8.2.01
December 15, 2005, 10:43 AM
dhofman
Everyone,

Thanks for your help. I have it working great with a the Strip function. I really need to get some updated manuals!! Roll Eyes