mIRC Home    About    Download    Register    News    Help

Topic Options
#104356 - 02/12/04 01:07 PM string manipulation question
thunk_ Offline
Bowl of petunias

Registered: 02/12/04
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.

Top
#104357 - 02/12/04 01:30 PM Re: string manipulation question
Zyzzyx26 Offline
Hoopy frood

Registered: 15/02/04
Posts: 714
Loc: Brasil
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

Top
#104358 - 02/12/04 01:49 PM Re: string manipulation question
Sigh Offline
Fjord artisan

Registered: 28/08/03
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),.)

Top
#104359 - 02/12/04 01:57 PM Re: string manipulation question
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
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

Top
#104360 - 02/12/04 02:03 PM Re: string manipulation question
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
Once again, somebody posts while I'm previewing my reply... story of my life.
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#104361 - 02/12/04 02:50 PM Re: string manipulation question
thunk_ Offline
Bowl of petunias

Registered: 02/12/04
Posts: 2
thanks! works like a charm cool

Top
#104362 - 02/12/04 03:53 PM Re: string manipulation question
Zyzzyx26 Offline
Hoopy frood

Registered: 15/02/04
Posts: 714
Loc: Brasil
Thanks Sigh and querty! smile I wasn't paying attention I suppose smirk
_________________________
"All we are saying is give peace a chance" -- John Lennon

Top