mIRC Home    About    Download    Register    News    Help

Print Thread
string manipulation question #104356 02/12/04 01:07 PM
Joined: Dec 2004
Posts: 2
T
thunk_ Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
T
Joined: Dec 2004
Posts: 2
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.

Re: string manipulation question #104357 02/12/04 01:30 PM
Joined: Feb 2004
Posts: 714
Z
Zyzzyx26 Offline
Hoopy frood
Offline
Hoopy frood
Z
Joined: Feb 2004
Posts: 714
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


"All we are saying is give peace a chance" -- John Lennon
Re: string manipulation question #104358 02/12/04 01:49 PM
Joined: Aug 2003
Posts: 314
S
Sigh Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
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),.)

Re: string manipulation question #104359 02/12/04 01:57 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: string manipulation question #104360 02/12/04 02:03 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Once again, somebody posts while I'm previewing my reply... story of my life.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: string manipulation question #104361 02/12/04 02:50 PM
Joined: Dec 2004
Posts: 2
T
thunk_ Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
T
Joined: Dec 2004
Posts: 2
thanks! works like a charm cool

Re: string manipulation question #104362 02/12/04 03:53 PM
Joined: Feb 2004
Posts: 714
Z
Zyzzyx26 Offline
Hoopy frood
Offline
Hoopy frood
Z
Joined: Feb 2004
Posts: 714
Thanks Sigh and querty! smile I wasn't paying attention I suppose smirk


"All we are saying is give peace a chance" -- John Lennon