From WikiChip
Difference between revisions of "mirc/commands/breplace"
< mirc‎ | commands

(Add'l syntax and examples)
(updated syntax+examples)
 
Line 4: Line 4:
 
== Synopsis ==
 
== Synopsis ==
 
  /breplace &binvar <oldvalue> <newvalue> [oldvalue newvalue...]
 
  /breplace &binvar <oldvalue> <newvalue> [oldvalue newvalue...]
 +
/breplace &binvar <old-char/value> <old-char/value> [old-char/value new-char/value...]
  
 
== Switches ==
 
== Switches ==
Line 11: Line 12:
 
* '''<oldvalue>''' - The old ASCII value to replaced (decimal 0-255)
 
* '''<oldvalue>''' - The old ASCII value to replaced (decimal 0-255)
 
* '''<newvalue>''' - The new ASCII value to replace the old one (decimal 0-255)
 
* '''<newvalue>''' - The new ASCII value to replace the old one (decimal 0-255)
 +
*'''Note:''' - Also accepts case-sensitive text characters/strings as parameters, using $asc(1st character of the string)
 
'''Note:''' This replaces individual bytes and does not allow replacing multi-byte patterns with new multi-byte patterns.<br />
 
'''Note:''' This replaces individual bytes and does not allow replacing multi-byte patterns with new multi-byte patterns.<br />
'''Note:''' Bytes are replaced only once, even if the new_value is the old_value for the next old/new pair.<br />
+
'''Note:''' Bytes are replaced only once, even if the new_value is the old_value for the next old/new pair. This means that it mimics the behavior of $replacex not $replace. However the replacements are made in reverse order, with the first pair being replaced last of all.<br />
 
'''Note:''' You can have multiple old/new number pairs, and if the count of numbers is an odd number greater than 2, the last unpaired number is ignored.<br />
 
'''Note:''' You can have multiple old/new number pairs, and if the count of numbers is an odd number greater than 2, the last unpaired number is ignored.<br />
 
'''Note:''' You cannot breplace within a portion of a binary &string unless you bcopy that section to a &temp where you perform the breplace then bcopy &temp back to the original &string/position.
 
'''Note:''' You cannot breplace within a portion of a binary &string unless you bcopy that section to a &temp where you perform the breplace then bcopy &temp back to the original &string/position.
 
== Example ==
 
== Example ==
<syntaxhighlight lang="mIRC">Alias Example {
+
<source lang="mIRC">Alias Example {
 
   ;Create a binary variable set it to \"Hello World\"
 
   ;Create a binary variable set it to \"Hello World\"
 
   bset -t &Example 1 Hello World
 
   bset -t &Example 1 Hello World
Line 25: Line 27:
 
   ;Echo our new string
 
   ;Echo our new string
 
   echo -a $bvar(&Example,1,$bvar(&Example,0)).text
 
   echo -a $bvar(&Example,1,$bvar(&Example,0)).text
}</syntaxhighlight>
+
}</source>
  
 
The above example will output:
 
The above example will output:
 
<pre>H3llo World</pre>
 
<pre>H3llo World</pre>
  
<syntaxhighlight lang="mIRC">
+
<source lang="mIRC">
 
Note that long strings can be replaced. The replace is on the entire token - not finding the 0 within the 10:
 
Note that long strings can be replaced. The replace is on the entire token - not finding the 0 within the 10:
 
//bset &a 7654321 10 | echo -a $bvar(&a,7654300-) | breplace &a 0 1 | echo -a $bvar(&a,7654300-)
 
//bset &a 7654321 10 | echo -a $bvar(&a,7654300-) | breplace &a 0 1 | echo -a $bvar(&a,7654300-)
Line 36: Line 38:
 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10
 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10
 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10
 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10
</syntaxhighlight>
+
</source>
  
<syntaxhighlight lang="mIRC">
+
<source lang="mIRC">
The replacement is not recursive, it does not find the 33's changed to 44's when it changes the existing 44's to 45's
+
The replacements are made in the same style as $replacexcs not $replace, but the replacement pairs are made in reverse order. Because of the reverse order, /breplace swaps the 11 for the 77 in the last pair before it can replace the 11 with the 88.
//bset &a 1 33 33 44 44 55 | echo -a $bvar(&a,1-) | breplace &a 33 44 44 45 | echo -a $bvar(&a,1-)
 
returns: 44 44 45 45 55
 
</syntaxhighlight>
 
  
<syntaxhighlight lang="mIRC">
+
//var %a 11 22 33 44 | bset &v 1 %a | breplace &v 11 88 44 66 11 77 | echo -a %a (original) | echo -a $bvar(&v,1-) (breplace) | echo -a $replace(%a,11,88,44,66,11,77,66,99) (replace) | echo -a $replacex(%a,11,88,44,66,11,77,66,99) (replacex)
The number of from/to byte pairs is an odd number greater than 2, so the last unpaired number is ignored without reporting an error:
+
result:
 +
11 22 33 44 (original)
 +
77 22 33 66 (breplace)
 +
88 22 33 99 (replace)
 +
88 22 33 66 (replacex)
 +
</source>
 +
 
 +
<source lang="mIRC">
 +
The first character of a string can substitute in place of a byte value, if it is non-numeric and is not UTF-8 encoded to more than 1 byte. In this example, the chr(233) is not replaced because there is no 1-byte character match. The next match fails because capital F is not a case-sensitive match for lower-case 'f'. The 'b' takes the place of byte value 98, and is replaced by $chr(33). The first character of 'abc' is found in the string, and is replaced by the 1st character of 'xyz'.
 +
 
 +
//bset -t &v 1 abcdefé | breplace &v abc xyz b 33 F g $chr(233) $chr(234) | echo -a $bvar(&v,1-) / $bvar(&v,1-).text
 +
result: x!cdefé
 +
</source>
 +
 
 +
<source lang="mIRC">
 +
The number of from/to byte pairs is an odd number greater than 2, so the last unpaired number is ignored without reporting an error, before the swaps are made in reverse-pair order:
 
//bset &a 1 13 10 13 10 99 | breplace &a 10 13 13 10 99 | echo -a $bvar(&a,1-)
 
//bset &a 1 13 10 13 10 99 | breplace &a 10 13 13 10 99 | echo -a $bvar(&a,1-)
 
returns: 10 13 10 13 99
 
returns: 10 13 10 13 99
</syntaxhighlight>
+
</source>
  
 
== Compatibility ==
 
== Compatibility ==
Line 62: Line 76:
 
* {{mIRC|/btrunc}}
 
* {{mIRC|/btrunc}}
 
* {{mIRC|/bcopy}}
 
* {{mIRC|/bcopy}}
* [[List of commands - mIRC|List of commands]]
+
* {{mIRC|$replacex}}
* [[List of identifiers - mIRC|List of identifiers]]
+
* {{mIRC|$replace}}
 
 
{{mIRC command list}}
 
 
 
[[Category:mIRC commands|breplace command - mIRC]]
 

Latest revision as of 21:50, 3 April 2019

The /breplace command can be used to replace an ASCII value by another value in a binary variable. Multiple replacements are allowed.

Synopsis[edit]

/breplace &binvar <oldvalue> <newvalue> [oldvalue newvalue...]
/breplace &binvar <old-char/value> <old-char/value> [old-char/value new-char/value...]

Switches[edit]

None

Parameters[edit]

  • <oldvalue> - The old ASCII value to replaced (decimal 0-255)
  • <newvalue> - The new ASCII value to replace the old one (decimal 0-255)
  • Note: - Also accepts case-sensitive text characters/strings as parameters, using $asc(1st character of the string)

Note: This replaces individual bytes and does not allow replacing multi-byte patterns with new multi-byte patterns.
Note: Bytes are replaced only once, even if the new_value is the old_value for the next old/new pair. This means that it mimics the behavior of $replacex not $replace. However the replacements are made in reverse order, with the first pair being replaced last of all.
Note: You can have multiple old/new number pairs, and if the count of numbers is an odd number greater than 2, the last unpaired number is ignored.
Note: You cannot breplace within a portion of a binary &string unless you bcopy that section to a &temp where you perform the breplace then bcopy &temp back to the original &string/position.

Example[edit]

Alias Example {
  ;Create a binary variable set it to "Hello World"
  bset -t &Example 1 Hello World
 
  ;Replace e (ASCII value 101) with 3 (ASCII value 51)
  breplace &Example 101 51
 
  ;Echo our new string
  echo -a $bvar(&Example,1,$bvar(&Example,0)).text
}

The above example will output:

H3llo World
Note that long strings can be replaced. The replace is on the entire token - not finding the 0 within the 10:
//bset &a 7654321 10 | echo -a $bvar(&a,7654300-) | breplace &a 0 1 | echo -a $bvar(&a,7654300-)
shows the last 22 bytes changing:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10
The replacements are made in the same style as $replacexcs not $replace, but the replacement pairs are made in reverse order. Because of the reverse order, /breplace swaps the 11 for the 77 in the last pair before it can replace the 11 with the 88.
 
//var %a 11 22 33 44 | bset &v 1 %a | breplace &v 11 88 44 66 11 77 | echo -a %a (original) | echo -a $bvar(&v,1-) (breplace) | echo -a $replace(%a,11,88,44,66,11,77,66,99) (replace) | echo -a $replacex(%a,11,88,44,66,11,77,66,99) (replacex)
result:
11 22 33 44 (original)
77 22 33 66 (breplace)
88 22 33 99 (replace)
88 22 33 66 (replacex)
The first character of a string can substitute in place of a byte value, if it is non-numeric and is not UTF-8 encoded to more than 1 byte. In this example, the chr(233) is not replaced because there is no 1-byte character match. The next match fails because capital F is not a case-sensitive match for lower-case 'f'. The 'b' takes the place of byte value 98, and is replaced by $chr(33). The first character of 'abc' is found in the string, and is replaced by the 1st character of 'xyz'.
 
//bset -t &v 1 abcdefé | breplace &v abc xyz b 33 F g $chr(233) $chr(234) | echo -a $bvar(&v,1-) / $bvar(&v,1-).text
result: x!cdefé
The number of from/to byte pairs is an odd number greater than 2, so the last unpaired number is ignored without reporting an error, before the swaps are made in reverse-pair order:
//bset &a 1 13 10 13 10 99 | breplace &a 10 13 13 10 99 | echo -a $bvar(&a,1-)
returns: 10 13 10 13 99

Compatibility[edit]

Added: mIRC v5.6
Added on: 03 Jun 1999
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.


See also[edit]