mIRC Home    About    Download    Register    News    Help

Print Thread
#176116 03/05/07 06:46 PM
P
pouncer
pouncer
P
Is it possible to do this by regex.

Take the string for e.g:

hello my name is Johnny and i am good

it should turn it into:

Hello my name is Johnny and I am good.

Caps first letter, turn i into I (if its i + chr32) and put a period at end of sentence


#176117 03/05/07 07:05 PM
Joined: Nov 2006
Posts: 1,552
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,552
Well, regarding THIS example there is no need for regex at all smile
Code:
var %text = hello my name is Johnny and i am good
echo -a $upper($left(%text,1)) $+ $replace($mid(%text,2),$+($chr(32),i,$chr(32)),$+($chr(32),I,$chr(32))) $+ $iif(($right(%text,1) != .),.)

But of course you're right, regexes are quite more handy...

Horstl #176120 03/05/07 08:16 PM
P
pouncer
pouncer
P
thanks horst, ya

perhaps the code can be smaller with regex

#176152 04/05/07 03:16 PM
Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
Yes regex could do complex things that would save loops sometimes. but u can do something easy such as horst did.

#176163 04/05/07 05:50 PM
Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
Code:
alias capitalise {
  var %text = $regsubex($regsubex($1,/(?<=^|[.!?] )(.)|(?<=^| )(i(?= |'|$))/g,$upper(\t)),/\bmirc\b/gi,mIRC)
  return %text $+ $iif($right(%text,1) !isin .!? && $gettok(%text,-1,32) isalnum,.)
}
alias cinput {
  if ($1 == on) .enable #input
  else .disable #input
}

#input off

on *:input:*:{
  if (!$istok(/ $readini($mircini,text,commandchar),$left($1,1),32)) && (!$ctrlenter) && (!$inpaste) {
    say $capitalise($1-)
    haltdef
  }
}

#input end


$capitalise(<string>) to return a capitalised string.

/cinput <on/off> to turn automatic text capitalisation on/off.


Link Copied to Clipboard