From WikiChip
Editing mirc/commands/breplace

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 1: Line 1:
{{mirc title|/breplace Command}}
+
The '''/breplace command''' can be used to replace an ASCII value by another value in a binary variable. Multiple replacements are allowed.
The '''/breplace''' command can be used to replace an ASCII value by another value in a binary variable. Multiple replacements are allowed.
 
  
 
== 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 10: Line 8:
  
 
== Parameters ==
 
== Parameters ==
* '''<oldvalue>''' - The old ASCII value to replaced (decimal 0-255)
+
* '''<oldvalue>''' - The old ASCII value to replaced
* '''<newvalue>''' - The new ASCII value to replace the old one (decimal 0-255)
+
* '''<newvalue>''' - The new ASCII value to replace the old one
*'''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:''' 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 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 ==
<source lang="mIRC">Alias Example {
+
<syntaxhighlight 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 27: Line 21:
 
   ;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
}</source>
+
}</syntaxhighlight>
  
 
The above example will output:
 
The above example will output:
 +
 
<pre>H3llo World</pre>
 
<pre>H3llo World</pre>
 
<source lang="mIRC">
 
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
 
</source>
 
 
<source lang="mIRC">
 
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)
 
</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-)
 
returns: 10 13 10 13 99
 
</source>
 
  
 
== Compatibility ==
 
== Compatibility ==
{{mIRC compatibility|5.6}}
+
Added: mIRC v5.6
  
 
== See also ==
 
== See also ==
 +
* [[List of commands - mIRC|List of commands]]
 +
* [[List of identifiers - mIRC|List of identifiers]]
 
* {{mIRC|$bvar}}
 
* {{mIRC|$bvar}}
 
* {{mIRC|$bfind}}
 
* {{mIRC|$bfind}}
 
* {{mIRC|/bread}}
 
* {{mIRC|/bread}}
 
* {{mIRC|/bset}}
 
* {{mIRC|/bset}}
* {{mIRC|/bunset}}
 
* {{mIRC|/bwrite}}
 
 
* {{mIRC|/btrunc}}
 
* {{mIRC|/btrunc}}
 
* {{mIRC|/bcopy}}
 
* {{mIRC|/bcopy}}
* {{mIRC|$replacex}}
+
 
* {{mIRC|$replace}}
+
{{mIRC command list}}
 +
 
 +
[[Category:MIRC commands]]

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)