mIRC Home    About    Download    Register    News    Help

Topic Options
#256687 - 09/02/16 08:26 PM $replace but only part of the string
lostay Offline
Nutrimatic drinks dispenser

Registered: 04/02/16
Posts: 7
Okay, let's say I have this:

Code:
var %x = I like bots, bananas, solutions.


If I want to replace only the second comma to " and" or something, how would I do that?

If I do:
Code:
$replace(%x,$chr(44), $chr(32) and)


The result will be: I like bots and bananas and solutions.
But I want it to be: I like bots, bananas and solutions.

Of course, I could just split the string into two, but that's not what I'm looking for (I want it to be able to do it with every string I give him)

Thanks in advance.

Top
#256688 - 09/02/16 08:31 PM Re: $replace but only part of the string [Re: lostay]
westor Offline
Hoopy frood

Registered: 27/12/08
Posts: 1511
Loc: Greece
Try use this method:

You will need $gettok (/help $gettok)

Code:
//var %text = I like bots, bananas, solutions. | echo -a $replace(%text,$gettok(%text,2,44) $+ $chr(44),$chr(32) and)
_________________________
Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-

Top
#256689 - 09/02/16 08:47 PM Re: $replace but only part of the string [Re: lostay]
Loki12583 Offline
Hoopy frood

Registered: 22/01/04
Posts: 1263
How does splitting the string prevent you from doing it generically?

All but last item: $gettok(%x,-2-1,44)
Last item: $gettok(%x,-1,44)


Edited by Loki12583 (09/02/16 08:50 PM)

Top
#256909 - 01/03/16 04:45 PM Re: $replace but only part of the string [Re: lostay]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
Code:
$deltok(%x,-1,44) and $gettok(%x,-1,44)


Code:
//var %x = I like bots, bananas, solutions. | echo -a $deltok(%x,-1,44) and $gettok(%x,-1,44)


Output:

"I like bots, bananas and solutions."

Top
#256912 - 01/03/16 04:57 PM Re: $replace but only part of the string [Re: hixxy]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3475
Loc: France
Tell us about what you don't like in $gettok(,-2-1,C) hixxy, cause it must be worth bumping this thread grin
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#256913 - 01/03/16 05:00 PM Re: $replace but only part of the string [Re: Wims]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
Sure: it doesn't work! Have you tried it? :p

Top
#256914 - 01/03/16 05:04 PM Re: $replace but only part of the string [Re: hixxy]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3475
Loc: France
I didn't but I just did now

Code:
//var %text = I like bots, bananas, solutions. | echo -a $gettok(%text,-2-1,44) and $gettok(%text,-1,44)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#256915 - 01/03/16 05:06 PM Re: $replace but only part of the string [Re: Wims]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
It does work actually. My bad, I was using it on an 'a, b and c.' string rather than 'a, b, c.'.

Top
#256916 - 01/03/16 05:09 PM Re: $replace but only part of the string [Re: hixxy]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3475
Loc: France
eheh, you could have argued that $deltok was shorter!
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top