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!

Remove spaces in strings 1

Status
Not open for further replies.

PhilBreau

Technical User
Dec 14, 2001
108
0
0
CA
I have records where I have to remove spaces. My preference is to have variable length strings with no spaces before or after field information. The field separaters are "|"

Example:

| John | Smith |
| Ann Marie | Jones |

I will probably read each field into string variables with strtok or strextract. I want to remove leading and trailing spaces.

Output would look like this:

|John|Smith|
|Ann Marie|Jones|

The important this is to remove space between the verticle bars and any printable character.


Thank you
 
Here's a function from my site to remove trailing spaces. If you use the strrev command to reverse your string, call this function a second time, and then use strrev once more to have your string back in the correct order, it should take care of trailing spaces.

func StripSpaces : string
param string targetline
integer str_length

strlen targetline str_length ;Get length of string

while str_length > 0 ;While the string has at least one character in it...
if rstrcmp targetline " " 1 ;Compare the first character in the string to a space
strdelete targetline 0 1 ;If the first character is a space, delete it from the string
else
exitwhile ;Else exit the while loop
endif
endwhile

return targetline ;Return modified string
endfunc

aspect@aspectscripting.com
 
That works great knob.

Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top