Checks the text given and adds the wanted character to the front of each word as needed.
; Usage $charcheck(TEXT,C)
; Example:
; That --> //echo -s $charcheck(#test tester #testing testing,35)
; Gives --> #test #tester #testing #testing
; Usage $charcheck(TEXT,C)
; Example:
; That --> //echo -s $charcheck(#test tester #testing testing,35)
; Gives --> #test #tester #testing #testing
alias charcheck {
var %t 1
while (%t <= $numtok($1,32)) {
var %front, %frontend = $instok(%frontend,$iif($left($gettok($1,%t,32),1) != $chr($2),$+($chr($2),$gettok($1,%t,32)),$gettok($1,%t,32)),0,32)
inc %t
}
return %frontend
}
easy way.
$chr(tokenNumber) $replace($remove(string,$chr(tokennumber) ),$chr(32),$chr(32) $+ $chr(tokenNumber))
$chr(35) $+ $replace($remove(lol lal #lol #test,$chr(35)),$chr(32),$chr(32) $+ $chr(35))
;--
#lol #lal #lol #test
x.x i dont like regex here is.. bla. mirc 6.16 is the best ;D
alias ctest {
var %t = $ticks, %x = 100, %test
while ( %x ) {
%test = $chr($2) $+ $replace($remove($1,$chr($2) ),$chr(32),$chr(32) $+ $chr($2))
dec %x
}
return simple. Time: $calc($ticks - %t) %test
}
nice..
//echo -a * $ctest(tehis #is a #test asd asd a #as asd # asd # asd ## a as a a aa sd a asd a asd a asd as asd asd asd asd asd as asd as dasd asd asdasd # asd a # asd # asda a # asd #asd as #a #asd #asda #reasa #adsaa #asd #asdae as asd a sdas asd as asd asd asd ad,35)
* simple. Time: 41 #tehis #is #a #test #asd #asd #a #as #asd #asd #asd # #a #as #a #a #aa #sd #a #asd #a #asd #a #asd #as #asd #asd #asd #asd #asd #as #asd #as #dasd #asd #asdasd #asd #a #asd #asda #a #asd #asd #as #a #asd #asda #reasa #adsaa #asd #asdae #as #asd #a #sdas #asd #as #asd #asd #asd #ad
40-43ms. basic code.
lol yeah i should have known why i was the person who found out mIRC translates to $n internally in the regsubex to do the actual substitution.
See in action:
//echo -a $regsubex($str(.,23),/(.)/g,$(\1,0))
Posted the wrong one :) $1- should also be $1
the fix is easy though:
alias charcheck return $regsubex($1,/(?<=\s|^)([^ $chr($2) ])/gx,$chr( [ $2 ] )\1)
Lindrian I would love to know how or why that regex is "so wrong in so many ways".
Edit: BTW the regex is much more efficient then using a while loop.
alias charcheck { var %c $chr($2) | return $regsubex($1,/(?<= |^)([^ $+ %c $+ ][^ ]*)(?= |$)/g,%c $+ \1) }
alias charcheck1 {
var %t 1
while (%t <= $numtok($1,32)) {
var %front, %frontend = $instok(%frontend,$iif($left($gettok($1,%t,32),1) != $chr($2),$+($chr($2),$gettok($1,%t,32)),$gettok($1,%t,32)),0,32)
inc %t
}
return %frontend
}
alias ctest {
var %t = $ticks, %x = 100
while (%x) {
noop $charcheck(tehis #is a #test asd asd a #as asd # asd # asd ## a as a a aa sd a asd a asd a asd as asd asd asd asd asd as asd as dasd asd asdasd # asd a # asd # asda a # asd #asd as #a #asd #asda #reasa #adsaa #asd #asdae as asd a sdas asd as asd asd asd ad ,35)
dec %x
}
echo -b Regex Time: $calc($ticks - %t)
var %t = $ticks, %x = 100
while (%x) {
noop $charcheck1(tehis #is a #test asd asd a #as asd # asd # asd ## a as a a aa sd a asd a asd a asd as asd asd asd asd asd as asd as dasd asd asdasd # asd a # asd # asda a # asd #asd as #a #asd #asda #reasa #adsaa #asd #asdae as asd a sdas asd as asd asd asd ad ,35)
dec %x
}
echo -b WhileLoop Time: $calc($ticks - %t)
}
just do /ctest
My average regex time was between 65-85 ms, while the while loop was between 700 and 800ms.