Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blank Spaces

Status
Not open for further replies.

marinos

Programmer
May 13, 2010
12
CY
Dear all,
i have small problem in progress 10.1b. Does anybody know how can i eliminate spaces or leading zero. For example:
i have a field with format char"x(10)". but the value is less than 10. How i avoid the spaces at the end, also the same for integer values e.g. ">>>>>9.99".

Thanks
Marinos
 
For character fields, use the TRIM, LEFT-TRIM, and RIGHT-TRIM functions to remove leading and trailing spaces.

I'm not sure what you mean by your numeric format example. The '>' is used in floating currency symbol formats, after a currency symbol, or in floating decimal formats. The numeric format symbol 'z' is used to suppress leading zeros.

 
Thanks,
but the trim function is not working for my program.
What i actually want is to erase any blank spaces in my output file.

Thanks again for help.

Marinos
 
You need to build a loop that examines each individual character in the field and cuts out spaces using the SUBSTRING function. Something like:
Code:
DEF VAR v-char-index as integer.
DEF VAR v-sample-field AS CHARACTER FORMAT "x(11)" INITIAL " 1234 5678 ".
v-sample-field = TRIM(v-sample-field). /* remove leading and trailing spaces */
REPEAT v-char-index = 2 to LENGTH(v-sample-field).  /* remove internal spaces */
  IF SUBSTRING(v-sample-field,v-char-index,1) = " "
  THEN v-sample-field = SUBSTRING(v-sample-field,1,v-char-index - 1) + SUBSTRING(v-sample-field,v-char-index + 1).
END.
DISPLAY v-sample-field LENGTH(v-sample-field).
 
On further reflection, the loop will not handle multiple contiguous spaces unless the field is processed right-to-left. The REPEAT statement should be:
Code:
REPEAT v-char-index = LENGTH(v-sample-field) to 2 by -1.
 
Thanks it was very helpful.

Regards
Marinos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top