Page 1 of 1

[Solved]ReplaceString() problem not my day today :(

Posted: Sun Oct 16, 2011 7:50 pm
by infratec
Hi,

during my work on ConvertGeoToDeg() I found a bug.
(I hope this is a real bug and not again a bug from me)

Code: Select all

Test$ = "- " + #DQUOTE$ + " -"
Debug Test$
If FindString(Test$, #DQUOTE$, 1) : Debug "found" : EndIf
ReplaceString(Test$, #DQUOTE$, "-")
Debug Test$
#DQUOTE$ is not replaced by ReplaceString()

Also chr(34) is not working.

Can someone confirm this, or point me to a fault of mine?

Bernd

Re: 4.51 ReplaceString() problem

Posted: Sun Oct 16, 2011 8:01 pm
by infratec
removed by me.

Re: 4.51 ReplaceString() problem

Posted: Sun Oct 16, 2011 8:02 pm
by luis

Code: Select all

Test$ = "- " + #DQUOTE$ + " -"
Debug Test$
If FindString(Test$, #DQUOTE$, 1) : Debug "found" : EndIf

Debug ReplaceString(Test$, #DQUOTE$, "-")
Not a bug.

You need to use the return of ReplaceString(). The docs could be more clear.

Re: [Solved]ReplaceString() problem not my day today :(

Posted: Sun Oct 16, 2011 8:20 pm
by infratec
Thanks Luis,

today is not my day :oops: :oops: :oops:

If I remember correct, I ran already in the same situation.
I'm getting old.

Sorry for the trouble,

Bernd

Re: [Solved]ReplaceString() problem not my day today :(

Posted: Mon Oct 17, 2011 7:20 am
by infratec
I just checked the help of ReplaceString():
Debug ReplaceString("This is Art", " is", " was") ; wird "This was Art" anzeigen
Debug ReplaceString("Hello again, hello again", "HELLO", "oh no...", #PB_String_NoCase, 10) ; wird "Hello again, oh no... again" anzeigen
So the help is wrong :!:

So please can a mod move this in the right section?

Bernd

Re: [Solved]ReplaceString() problem not my day today :(

Posted: Mon Oct 17, 2011 8:06 am
by Kiffi
infratec wrote:So the help is wrong :!:
no, it isn't.

Greetings ... Kiffi

Re: [Solved]ReplaceString() problem not my day today :(

Posted: Mon Oct 17, 2011 1:05 pm
by luis
The help is not wrong, but it could be better and the function behavior too IMO.

1) The help doesn't mention what the return value is.
You have to deduce looking and trying the examples it is a copy of the source string modified by the replace operation. So the original string is not touched.

2) The examples in the help are using numeric constants instead of the symbolic constants #PB_String_*, so again one is guessing what is what, and you have to check the numerical value of the constants to know for sure.

3) When using the #PB_String_InPlace I would prefer the return value to not be "invalid" (actually it seem to be the previous return value of the last not-in-place replacement) and could easily be the original string, now modified in place. I would find this behavior more useful and coherent (a result string would always be returned), no new string would be allocated anyway, so it should not cause a speed penalty.