|
Joined: Aug 2003
Posts: 27
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2003
Posts: 27 |
make it so that $replace can't be used against itself!!!!!
e.g., %n = $replace($1-,a,n,n,a) changes "anan" to "aaaa"
when in fact i just want it to swap the two chars
|
|
|
|
Joined: Dec 2002
Posts: 774
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 774 |
I made this while back:
replace2 {
if ( $isid ) {
var %temp = $1
var %check
var %i = 1, %ii = $0 / 2
while ( %i <= %ii ) {
var %replace = $($+($,$calc( %i * 2 )),2)
var %replace2 = $($+($,$calc( %i * 2 + 1)),2)
var %j = 1
while ( $pos( $1 , %replace , %j ) ) {
var %pos = $pos( $1 , %replace , %j )
var %replacecheck = $calc( %pos + $replacecheck( %check , %pos) )
var %replacecheck = $iif(%replacecheck > 0,$ifmatch,0)
var %mid1 = $iif(%pos > 1,$mid( %temp , 0 , $calc( %replacecheck - 1 ) ) )
var %mid2 = $mid( %temp , $calc( %replacecheck + $len( %replace ) ) , $mid( %temp , %replacecheck , 0 ) )
var %temp = $+( %mid1 , %replace2 , %mid2 )
var %check = $+( %check , %pos , . , $len( %replace2 ) , . , $len( %replace ) , - )
inc %j
}
inc %i
}
return %temp
}
else echo $color(info) -a REPLACE2 is identifier
}
replacecheck {
var %temp = 0
if (( isid ) && ( $1 )) {
var %pos = $2
var %i = 1
while ( $gettok($1,%i,45) ) {
if ( $gettok($gettok($1,%i,45),1,46) <= %pos ) {
%temp = %temp + $gettok($gettok($1,%i,45),2,46)
%temp = %temp - $gettok($gettok($1,%i,45),3,46)
}
inc %i
}
}
return %temp
}
//if ( khaled isgod ) echo yes | else echo no
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
no way buddy, i use that feature of $replace all the time.
just do this for ya replace
%n = $replace($1-,a,~,n,a,~,n)
changes "anan" to "~n~n" to "~a~a" to "nana"
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Here's a faster/shorter solution: alias replacex {
if $0 == 1 || $0 !& 1 { echo -seic info * Invalid parameters: $!replacex | halt }
var %i = 2, %s = $1, %c = $iif($prop != cs,i)
while %i < $0 {
!.echo -q $regsub(%s,$+(/\Q,$replacecs($ [ $+ [ %i ] ],\E,\E\\E\Q),\E(?=[^\n\r]*(?:$|\n))/g,%c),$+($lf,$replace($ [ $+ [ $calc(%i + 1) ] ],\,\\,$,\$),$cr),%s)
inc %i 2
}
$iif($isid,return,echo -a) $remove(%s,$cr,$lf)
} Note: if you use the .cs property, like $replacex(string,one,two,three,four).cs, it becomes case-sensitive, ie equivalent to $replacecs().
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Aug 2003
Posts: 27
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2003
Posts: 27 |
1. I'm not your buddy 2. i do not merely wish to swap 2 chars, i wish to replace large groups of chars, e.g., $replce($1-,a,z,b,y,c,x,d,w....), 3. in maintaining standard, 'predictable' output, khaled has tried to make mirc functions as similar to their c/c++/perl/whatever counterparts as possible; this should be no exception 4. the fact that you 'use this feature all the time' is not compelling enough for this bug to be ignored
|
|
|
|
Joined: Aug 2003
Posts: 27
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2003
Posts: 27 |
|
|
|
|
Joined: Dec 2002
Posts: 3,138
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,138 |
How is it a bug? At worst it is a minor inconsistency.
A) It doesn't crash mIRC. B) The way it works doesn't go against what it says in the helpfile.
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
1. Im sorry your antisocial, everyones my buddy (i might get a free beer that way) 2. well how to do that was explained, if it doesnt fit your requirements a short script can do a single pass search and replace (qwerty even wrote ya one) 3. are you sepeculating on what khaled was doing or can you back that up with a comparable replace function? 4. the fact that you call it a bug multiple times doesnt make it one either, and the fact that I and others well be using this feature of the $replace is a verygood reason not to change the feature (behavour would have been a better word i guess). heres an example of something that might need/use this behavour
setup {
window -c @window
;
; a window exists as follows...
window -el -t15,30,45,60,75 @window
;
; example line in window
aline -l @window $+(first,$chr(9),second,$chr(9),third,$chr(9),forth,$chr(9),fifth,$chr(9),sixth)
aline -l @window -
aline -l @window $replace($+(--->first,$chr(9),-->second,$chr(9),->third,$chr(9),>forth,$chr(9),->fifth,$chr(9),--->sixth),-,$chr(160))
}
;
example1 {
rline @window 1 $replace( $+($chr(2),$line(@window,1,1)) ,$chr(9),$+($chr(9),$chr(2)) ,$+($chr(2),$chr(2)),$null )
}
;
example2 {
rline @window 3 $replace( $+(-,$line(@window,3,1)) ,$chr(160),-, $chr(9),$chr(9) $+ - ,------->,>------- ,>-,> ,-,$chr(160) )
}
/setup /example1 ;^ switches bold of and on (not the same as just adding a bold at the front due to the way Tabs work /example2 ;^ pushes across the text tell 8 squares then cycles the pushing pointer Each of those examples could be used in a legit type script, and rely apon the behavour of $replace to rescan the text after each search and replace value.
|
|
|
|
|