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!

Striping Leading spaces

Status
Not open for further replies.

JGoudie

Programmer
Jun 17, 2002
16
0
0
CA
how would i strip leading spaces from say text like this:

" Text is here"

i just put quotes around the text to show the spaces in front.

i tried a little function something like this, but it doesn't seem to be doing what i want it to do.

func StripLSpaces : string
param string targetline

string result,char
integer str_length,pos,match

strlen targetline str_length
str_length--
result = targetline

for pos = 0 UPTO str_length
substr char targetline pos 1
strcmp char " " match
if match = 0
strdelete result pos 1
else
exitfor
endif
endfor

return result
endfunc ; StripLSpaces function

its probably a simple mistake i'm doing, I will keep playing with it and try and figure out whtas wrong
 
Here's the function I came up with:

func StripLSpaces : string
param string targetline

integer str_length

strlen targetline str_length

while str_length > 0
if rstrcmp targetline " " 1
strdelete targetline 0 1
else
exitwhile
endif
endwhile

return targetline
endfunc ; StripLSpaces function

The first problem I was running into with your function was that the line if match = 0 needed to be changed to if match == 0 (one = means assignment, while two = checks for equality). When I made that change, I was seeing some odd output. This was due to the lengths of targetline and result changing after the first strdelete command. That is why my function did things a little differently so it did not have to rely on the length of the string.
 
thank you knob.

much appreciated, i understand what was wrong now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top