|
Joined: Feb 2016
Posts: 7
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Feb 2016
Posts: 7 |
Okay, let's say I have this: 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: $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
|
Hoopy frood
Joined: Dec 2008
Posts: 1,515 |
Try use this method: You will need $gettok (/help $gettok)
//var %text = I like bots, bananas, solutions. | echo -a $replace(%text,$gettok(%text,2,44) $+ $chr(44),$chr(32) and)
|
|
|
|
Joined: Jan 2004
Posts: 1,358
Hoopy frood
|
Hoopy frood
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
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
$deltok(%x,-1,44) and $gettok(%x,-1,44) //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,150
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,150 |
Tell us about what you don't like in $gettok(,-2-1,C) hixxy, cause it must be worth bumping this thread
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
Sure: it doesn't work! Have you tried it? :p
|
|
|
|
Joined: Jul 2006
Posts: 4,150
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,150 |
I didn't but I just did now //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
Hoopy frood
|
Hoopy frood
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,150
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,150 |
eheh, you could have argued that $deltok was shorter!
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
|