mIRC Homepage
Posted By: BoredNL $replace - 31/08/03 10:12 PM
//echo $replace(this is just an example,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h,i,i,j,j,k,k,l,l,m,m,n,n,o,o,p,p,q,q,r,r,s,s,t,t,u,u,v,v,w,w,x,x,y,y,z,z,a)
all this does is returns all a's. (aaaa aa aaaa aa aaaaaaa)
I don't want replace to work progressively, I want it to turn all of the original a's into b's, and all of the original b's into c's. Right now it's turning all of the a's into b's, then every b (including the a's that were turned into b's) into c's, and so on and so forth. This is pointless and annoying. frown Does anyone know of any workaround?

-edit
I sure hope I don't have to go letter by letter..
Posted By: Iori Re: $replace - 31/08/03 11:15 PM
That is the way $replace has always worked, from left to right.
Posted By: ClickHeRe Re: $replace - 31/08/03 11:46 PM
Then change the replace order...
Posted By: BoredNL Re: $replace - 01/09/03 03:38 AM
That doesn't make sense.. Whatever order I use will still end with skewed results. I'd have to go character by character, and that is extremely CPU intensive.

The workaround I've managed is to use $replacecs with only lower-case letters for input, replacing letters with uppercase ones, then converting the output back to lowercase, but I'd really rather create a better script than this that also utilizes a minimum amount of CPU processes..
Posted By: Doomstars Re: $replace - 01/09/03 03:42 AM
I hate this too. Well, strongly dislike. Maybe something like the below would be a good feature suggestion.

$replace(string,substring,newstring,N) where if N equals 1 if it the way it works now. If N equals 2 it will not modify any newstring additions.
Posted By: BoredNL Re: $replace - 01/09/03 03:52 AM
or $replace(string,substring,newstring,substring,newstring).npr where npr stands for non-progressive.
Posted By: starbucks_mafia Re: $replace - 01/09/03 06:07 PM
A property for $replace to behave like that would be nice. If all you want to do is replace single characters like that though then the scripted version is quite simple really:
Code:
char_replace {
  ; Usage: $char_replace(string,char,newchar,...,charN,newcharN)
  var %i = 2, %j = 3, %c = 1
  bset -t &string 1 $1
  while $eval($+($,%j),2) != $null {
    bset &chars %c $asc($eval($+($,%i),2)) $asc($ifmatch)
    inc %i 2
    inc %j 2
    inc %c 2
  }
  breplace &string [ $bvar(&chars,1-) ]
  return $bvar(&string,1-).text
}


//echo $char_replace(this is just an example,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h,i,i,j,j,k,k,l,l,m,m,n,n,o,o,p,p,q,q,r,r,s,s,t,t,u,u,v,v,w,w,x,x,y,y,z,z,a)
echoes uijt jt kvtu bo fybnqmf

Remember that only works for replacing single characters though.
Posted By: Raccoon Re: $replace - 01/09/03 09:00 PM
actually /breplace is non-progressive like this, and is a lot faster than your loop.
The only exception is that /breplace can only handle single-byte (character) replacements, and is not useful if you want to replace letter pairs or words with other words.

For this use however, /breplace is the breakfast of champions.
Posted By: starbucks_mafia Re: $replace - 01/09/03 09:12 PM
Yes I know /breplace behaves like that, that's why I used it in my alias. The loop is there so that the parameters can be given as characters instead of ASCII codes.
© mIRC Discussion Forums