$charcheck

By Scakk on Oct 28, 2008

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
}

Comments

Sign in to comment.
dashh   -  Feb 22, 2009

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.

 Respond  
Mpdreamz   -  Dec 01, 2008

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)

 Respond  
TheImrac   -  Dec 01, 2008

Just for reference Mpdreamz, $n doesn't work in the replacement part, no idea why.

 Respond  
Mpdreamz   -  Nov 29, 2008

Nothing wrong with regsubex Lindrian it was designed to do text replacing so why not take advantage of it ?

Not to say the TheImrac's regex couldn't be shortened somewhat:

alias charcheck return $regsubex($1-,/(?<=\s|^)([^ $chr($2) ])/gx,$chr($2)\1)

but thats not really an issue :_

 Respond  
TheImrac   -  Nov 01, 2008

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.

 Respond  
^Neptune   -  Oct 31, 2008

Thelmrac: That regex is so wrong in so many ways its just sad. You should abuse regex for such simple tasks, it's just stupid.

That's not stupid at all. He shortened it into one line.

 Respond  
Scakk   -  Oct 31, 2008

Lindrian .. I do not use 6.35.

 Respond  
Lindrian   -  Oct 31, 2008

Works perfectly fine here, Scakk, on mIRC 6.35.

Thelmrac: That regex is so wrong in so many ways its just sad. You should abuse regex for such simple tasks, it's just stupid.

 Respond  
TheImrac   -  Oct 28, 2008
alias charcheck { var %c $chr($2) | return $regsubex($1,/(?<= |^)([^ $+ %c $+ ][^ ]*)(?= |$)/g,%c $+ \1) }
 Respond  
Scakk   -  Oct 28, 2008

Lindrian.. Your gives me

  • Invalid format: $iif (line 18, Goofy)
 Respond  
Lindrian   -  Oct 28, 2008

I'd use something much more simple:

alias charcheck {
  var %a 1,%b $chr($2),%c
  tokenize 32 $1
  while $($ $+ %a,2) != $null {
    var %d $v1,%c %c $iif($left(%d,1) != %b,%b) $+ %d
    inc %a
  }
  return %c
}
 Respond  
Jace   -  Oct 28, 2008

Cool Scakk.Can be used for games and stuff i can see.Like for money.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.