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

Just starting out? Need help? Post your questions and find answers here.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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
Last edited by infratec on Sun Oct 16, 2011 8:18 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: 4.51 ReplaceString() problem

Post by infratec »

removed by me.
Last edited by infratec on Sun Oct 16, 2011 8:19 pm, edited 1 time in total.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: 4.51 ReplaceString() problem

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

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

Post by Kiffi »

infratec wrote:So the help is wrong :!:
no, it isn't.

Greetings ... Kiffi
Hygge
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply