mIRC Home    About    Download    Register    News    Help

Print Thread
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.

Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
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 <-
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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.
Joined: Sep 2005
Posts: 2,881
H
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."

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Tell us about what you don't like in $gettok(,-2-1,C) hixxy, cause it must be worth bumping this thread grin


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Sure: it doesn't work! Have you tried it? :p

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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)


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2005
Posts: 2,881
H
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.'.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
eheh, you could have argued that $deltok was shorter!


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard