OK, next string question

Stellaferox

Active Member
Licensed User
Hi, again a string question. I am working on a datastring replacing and deleting characters which I dont want but the StrRemove and StrReplace function doesnt work in the following example

D$ = "1, 0" & CRLF & "2, 0" & "3, 0) & CRLF 'spaces after comma intended

For i = 0 to StrLength(D$)-1
k = StrAt(D$,i)
IF k = " " then 'also ASC(k) = 32 and k = chr(32) dont work
StrRemove(D$," ", 1)
END IF
NEXT

(The reason I am using this FOR next loop is that it also checks for TABS and commas but this code is not included here)
Now the program passes the IF then condition but doesnt remove (or replace the space with another character). Is this due to the FOR NEXT condition in which the string function is stored and if yes how do I edit a string in a function in which the string itself is examined? Or could it be that a DO WHILE {as long as there are spaces in this string -> remove them} function works better, and if yes how do I state the condition to be fulfilled?
I can imagine that after editing, the D$ and i-counter isnt updated in the FOR NEXT loop.
thnx again
Marc
 

Stellaferox

Active Member
Licensed User
Erel, OK, I understand, but then I am getting an IndexOutOfRangeException with the k = StrAt(D$,i) statement... the i-counter CAN go past the string if it is shortened truncated in the loop, yes?
 

petrbury

Member
Licensed User
Hi, I don't thing that you can solve the problem by decrementing i, because the end condition for " For - Next " loop remains still the same. I thing, you should use strReplace(D$," ","") for removing spaces ( if I understand correct what do you want ).
Petr
 

petrbury

Member
Licensed User
Yes, and maybe it could be done by the other way :

If strIndexOf(D$," ",0) <> -1 then D$ = strReplace(D$," ","")

And you don't need to use any loop.

Petr
 
Top