mIRC Homepage
Posted By: thunk_ string manipulation question - 02/12/04 01:07 PM
Hello, since I am quite new to mIRC scripting I am having trouble with a string manipulation I want to perform.

I want to remove all the dots ( . ) in the last 4 characters of a string only if there are any.

on 1:TEXT:*:#some_channel:{
if (nick = some_nick) {
if (. isin $right($1-,4)) <something_should_come_here>
}
}

I am able to remove the dots on the 4 last chars but then I get only the last 4 chars minus the dot with $remove($right($1-,4),.)

I have a string with alot of dots but I want to remove the . in the last 4 chars only.
Sorry for the n00b question but I can't seem to figure this out by myself.
Any help appreciated.
Posted By: Zyzzyx26 Re: string manipulation question - 02/12/04 01:30 PM
Code:
on ^*:TEXT*:#: {
  haltdef
  var %a = $+(1-,$calc($numtok($1-,32) - 1)), %b = $gettok($1-,%a,32), %c = $remove($right($gettok($1-,-1,32),4),.)
  echo $color(text) -tlbfm %b %c
}

This is not tested! Please tell me how it does.

Zyzzyx smile
Posted By: Sigh Re: string manipulation question - 02/12/04 01:49 PM
The last word may be 2 or less characters, such as "my text here. a." which is where handling it with $gettok would fail. I'd use

Code:
$left($1-,-4) $+ $remove($right($1-,4),.)
Posted By: qwerty Re: string manipulation question - 02/12/04 01:57 PM
thunk didn't say he wanted to remove the dots from the last word, just from the last 4 chars. Even if he had though, your script takes the last 4 chars from the last word and removes all dots from there; if the last word is longer than 4 chars, all but the last 4 chars of that word will be lost (eg if the last word is "ab.cd.ef.gh", your script would turn it to "fgh" and not the correct "ab.cd.efgh").

I'd use something like this:
Code:
on ^*:text:*:#: if . isin $right($1-,4) { echo -mbflirt # $+(&lt;,$nick,&gt;) [color:red]$left($1-,-4) $+[/color] $remove($v2,.) | halt }
The red part is probably what thunk was missing.
Note: this only works on mIRC 6.16 or newer (it can be easily modified to work for older versions though).

As a sidenote, and this is not for the OP's problem, instead of
var %a = $+(1-,$calc($numtok($1-,32) - 1)), %b = $gettok($1-,%a,32)
you can just use
var %b = $deltok($1-,-1,32)
And, btw, $0 = $numtok($1-,32)
Posted By: qwerty Re: string manipulation question - 02/12/04 02:03 PM
Once again, somebody posts while I'm previewing my reply... story of my life.
Posted By: thunk_ Re: string manipulation question - 02/12/04 02:50 PM
thanks! works like a charm cool
Posted By: Zyzzyx26 Re: string manipulation question - 02/12/04 03:53 PM
Thanks Sigh and querty! smile I wasn't paying attention I suppose smirk
© mIRC Discussion Forums