[Implemented] ReplaceString: Add opt. para. [,NbOccurences]

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

[Implemented] ReplaceString: Add opt. para. [,NbOccurences]

Post by IceSoft »

String$ = ReplaceString(String$, StringToFind$, StringToReplace$ [, Mode [, StartPosition]])

I cannot say: Replace only the first occurence of a search string.
Last edited by IceSoft on Thu Apr 15, 2010 5:41 am, edited 1 time in total.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: ReplaceString has no parameter for NbOccurences

Post by Fred »

Where is the bug ?
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: ReplaceString has no parameter for NbOccurences

Post by IceSoft »

ReplaceString iterating trough the whole string...I miss the occurence parameter for stopping the iteration e.g. after the first replace

Code: Select all

s1.s = "abcdeabcdeabcdeabcde"
s2.s = "ab"
Debug s1
String$ = ReplaceString(s1, s2, "AB" , #PB_String_InPlace, 1)
Debug s1 ; Result: ABcdeABcdeABcdeABcde, but I want: ABcdeabcdeabcdeabcde
ReplaceString have also have to have the NbOccurences parameter as the RemoveString has:

Code: Select all

String$ = RemoveString(String$, StringToRemove$ [, Mode [, StartPosition [, NbOccurences]]])
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: ReplaceString has no parameter for NbOccurences

Post by Arctic Fox »

Isn't this a feature request then? :wink:
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: ReplaceString has no parameter for NbOccurences

Post by IceSoft »

Arctic Fox wrote:Isn't this a feature request then? :wink:
Yes for all who not using ReplaceString at the moment.
If you use it...than it is a bug.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: ReplaceString has no parameter for NbOccurences

Post by Rings »

moved....
SPAMINATOR NR.1
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: ReplaceString has no parameter for NbOccurences

Post by IceSoft »

Rings wrote:moved....
Please add this optional parameter. You know: it is more a wrong design as a feature wish.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: ReplaceString has no parameter for NbOccurences

Post by freak »

Just because you want it doesn't make it wrong not to have it :P
quidquid Latine dictum sit altum videtur
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: ReplaceString has no parameter for NbOccurences

Post by Seymour Clufley »

+1
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: ReplaceString has no parameter for NbOccurences

Post by IceSoft »

freak wrote:Just because you want it doesn't make it wrong not to have it :P
In a real programmer life I can find more examples on which you want ONLY replace one occurence. :D

So my wish is:
Add a ReplaceString which is not searching through a string...a replace on a given position is enough.

For the actual implemented ReplaceString... please add the forgotten optional parameter:[, NbOccurences].
For example see RemoveString(...):
String$ = RemoveString(String$, StringToRemove$ [, Mode [, StartPosition [, NbOccurences]]])
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Post Reply