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!

strdelete two work the other does not?

Status
Not open for further replies.

DMS500Tech

Technical User
Dec 22, 2004
39
0
0
US
Same Scipt, 3 senerios, The first 2 work perfect everytime but the 3rd (searching for a "1")will not work. The first searches for "/" 2nd for "2" and they loop like they are suppose to. The third searches for a "1" and finds the first occurance then stops. I don't get it!

PROC MAIN
string FileName
integer position
FileName = "1/2/1/2/1/26/17"
position = 1
while (Position !=0)
strfind FileName "/" Position
if failure
Position = 0
else
strdelete FileName Position 1
endif
endwhile
usermsg FileName
endproc

PROC MAIN
string FileName
integer position
FileName = "1/2/1/2/1/26/17"
position = 1
while (Position !=0)
strfind FileName "2" Position
if failure
Position = 0
else
strdelete FileName Position 1
endif
endwhile
usermsg FileName
endproc

PROC MAIN
string FileName
integer position
FileName = "1/2/1/2/1/26/17"
position = 1
while (Position !=0)
strfind FileName "1" Position
if failure
Position = 0
else
strdelete FileName Position 1
endif
endwhile
usermsg FileName
endproc
 
Okay, I just tried a senerio that I had not tried earlier.
it is the first character that it the probelem. If the test string starts with a 1 and you search for a 1 it removes the first then stops. If the first character is changed to soemthing else it then loops correctly. same with the other 2 search character. If it is the first character in the string it removes the first then stops looping. If it is not the first character it loops correctly.
Is there a work around for this?
I really don't see why this is an issue unless it is because the characters shift left after the first loop. Can someone explain this to me.
 
Try this:

Code:
PROC MAIN
string FileName
integer position
FileName = "1/2/1/2/1/26/17"
position = 1
while (Position !=-1)
   strfind FileName "1" Position
   if failure
      Position = -1
   else
      strdelete FileName Position 1
   endif
endwhile
usermsg FileName
endproc

I think the problem was the '1' in the third example was in Position 0, and you were using that value as an escape from the while. By using -1, it is imposible to accidently escape if the first character is what you're looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top