mIRC Home    About    Download    Register    News    Help

Print Thread
$replace #45864 31/08/03 10:12 PM
Joined: Jan 2003
Posts: 154
B
BoredNL Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Jan 2003
Posts: 154
//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.

- Wherever you go there you are.[color:lightgreen]
Re: $replace #45865 31/08/03 11:15 PM
Joined: Aug 2003
Posts: 1,831
I
Iori Offline
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
That is the way $replace has always worked, from left to right.

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

Re: $replace #45867 01/09/03 03:38 AM
Joined: Jan 2003
Posts: 154
B
BoredNL Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Jan 2003
Posts: 154
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..


- Wherever you go there you are.[color:lightgreen]
Re: $replace #45868 01/09/03 03:42 AM
Joined: Dec 2002
Posts: 339
D
Doomstars Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Dec 2002
Posts: 339
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.

Re: $replace #45869 01/09/03 03:52 AM
Joined: Jan 2003
Posts: 154
B
BoredNL Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Jan 2003
Posts: 154
or $replace(string,substring,newstring,substring,newstring).npr where npr stands for non-progressive.


- Wherever you go there you are.[color:lightgreen]
Re: $replace #45870 01/09/03 06:07 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: $replace #45871 01/09/03 09:00 PM
Joined: Feb 2003
Posts: 2,624
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,624
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!
Re: $replace #45872 01/09/03 09:12 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.