|
Joined: Jan 2003
Posts: 154
Vogon poet
|
OP
Vogon poet
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.  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]
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
Joined: Aug 2003
Posts: 1,831 |
That is the way $replace has always worked, from left to right.
|
|
|
|
Joined: Jan 2003
Posts: 249
Fjord artisan
|
Fjord artisan
Joined: Jan 2003
Posts: 249 |
Then change the replace order...
|
|
|
|
Joined: Jan 2003
Posts: 154
Vogon poet
|
OP
Vogon poet
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]
|
|
|
|
Joined: Dec 2002
Posts: 343
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Dec 2002
Posts: 343 |
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.
|
|
|
|
Joined: Jan 2003
Posts: 154
Vogon poet
|
OP
Vogon poet
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]
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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: 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 fybnqmfRemember that only works for replacing single characters though.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
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!
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
|