mIRC Home    About    Download    Register    News    Help

Print Thread
#45864 31/08/03 10:12 PM
B
BoredNL
BoredNL
B
//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..

Last edited by BoredNL; 31/08/03 10:14 PM.
#45865 31/08/03 11:15 PM
I
Iori
Iori
I
That is the way $replace has always worked, from left to right.

#45866 31/08/03 11:46 PM
Joined: Jan 2003
Posts: 247
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 247
Then change the replace order...

#45867 01/09/03 03:38 AM
B
BoredNL
BoredNL
B
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..

#45868 01/09/03 03:42 AM
Joined: Dec 2002
Posts: 341
D
Pan-dimensional mouse
Offline
Pan-dimensional mouse
D
Joined: Dec 2002
Posts: 341
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.

#45869 01/09/03 03:52 AM
B
BoredNL
BoredNL
B
or $replace(string,substring,newstring,substring,newstring).npr where npr stands for non-progressive.

#45870 01/09/03 06:07 PM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
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.

#45871 01/09/03 09:00 PM
Joined: Feb 2003
Posts: 2,737
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,737
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.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
#45872 01/09/03 09:12 PM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
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.


Link Copied to Clipboard