mIRC Home    About    Download    Register    News    Help

Print Thread
$replace but only part of the string #256687 09/02/16 08:26 PM
Joined: Feb 2016
Posts: 7
L
lostay Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
L
Joined: Feb 2016
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.

Re: $replace but only part of the string [Re: lostay] #256688 09/02/16 08:31 PM
Joined: Dec 2008
Posts: 1,512
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,512
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? -> https://irc.chathub.org <-
Re: $replace but only part of the string [Re: lostay] #256689 09/02/16 08:47 PM
Joined: Jan 2004
Posts: 1,330
L
Loki12583 Online
Hoopy frood
Online
Hoopy frood
L
Joined: Jan 2004
Posts: 1,330
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)

Last edited by Loki12583; 09/02/16 08:50 PM.
Re: $replace but only part of the string [Re: lostay] #256909 01/03/16 04:45 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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."

Re: $replace but only part of the string [Re: hixxy] #256912 01/03/16 04:57 PM
Joined: Jul 2006
Posts: 3,827
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,827
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
Re: $replace but only part of the string [Re: Wims] #256913 01/03/16 05:00 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Sure: it doesn't work! Have you tried it? :p

Re: $replace but only part of the string [Re: hixxy] #256914 01/03/16 05:04 PM
Joined: Jul 2006
Posts: 3,827
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,827
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
Re: $replace but only part of the string [Re: Wims] #256915 01/03/16 05:06 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
It does work actually. My bad, I was using it on an 'a, b and c.' string rather than 'a, b, c.'.

Re: $replace but only part of the string [Re: hixxy] #256916 01/03/16 05:09 PM
Joined: Jul 2006
Posts: 3,827
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,827
eheh, you could have argued that $deltok was shorter!


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net