From WikiChip
Editing mirc/token manipulation

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|Token Manipulation}}
+
{{mIRC Guide}}
 +
 
 
If you are like many people who are coming from another programming language it might come as a surprise to you that there are no true arrays in mSL. This is because the paradigm is a little different: an array in mSL can be thought of as simply a list or vector of tokens. In mSL, a '''token''' is simply a string of characters that is separated by a single, unique character. mIRC provides an extensive set of identifiers and commands to help you manipulate this list of tokens.
 
If you are like many people who are coming from another programming language it might come as a surprise to you that there are no true arrays in mSL. This is because the paradigm is a little different: an array in mSL can be thought of as simply a list or vector of tokens. In mSL, a '''token''' is simply a string of characters that is separated by a single, unique character. mIRC provides an extensive set of identifiers and commands to help you manipulate this list of tokens.
  
Line 6: Line 7:
 
To better understand this concept; let's consider a simple alias that returns the day of the week from a given Nth day. In this case, our list of tokens will look something like this:
 
To better understand this concept; let's consider a simple alias that returns the day of the week from a given Nth day. In this case, our list of tokens will look something like this:
  
<pre>Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday</pre>
+
<pre>Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday</pre>
  
 
The first thing you can see is that we have the tokens (in this case, the days of the week) separated by a comma. In this example, the comma is called a delimiter. In mSL, a '''delimiter''' is a single character used to specify the boundary between two separate tokens in a list. The example above also has a special name: '''comma-separated values''' ('''CSV''').
 
The first thing you can see is that we have the tokens (in this case, the days of the week) separated by a comma. In this example, the comma is called a delimiter. In mSL, a '''delimiter''' is a single character used to specify the boundary between two separate tokens in a list. The example above also has a special name: '''comma-separated values''' ('''CSV''').
Line 21: Line 22:
 
     halt
 
     halt
 
   }
 
   }
   var %days = Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
+
   var %days = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
 
   return $gettok(%days, $1, 44)
 
   return $gettok(%days, $1, 44)
 
}</syntaxhighlight>
 
}</syntaxhighlight>
Line 46: Line 47:
 
var %newList = $instok(<list>, <token>, <Nth_pos>, <code_point>)</syntaxhighlight>
 
var %newList = $instok(<list>, <token>, <Nth_pos>, <code_point>)</syntaxhighlight>
  
The major difference between $instok and $addtok is that $addtok will not append a token that is already found in the string while $instok will. &lt;Nth_pos&gt; is the position of where the token should be placed. For example 5 will be the 5th element. A negative number can be used as well to indicate the Nth token from the end instead of the begging. For example -1 is the 2nd to last element, or the 1 element before the last element.
+
The major difference between $instok and $addtok is that $addtok will not append a token that is already found in the string while $instok will. &lt;Nth_pos&gt; is the position of where the token should be placed. For example 5 will be the 5th element. A negative number can be used as well to indicate the Nth token from the end instead of the begging. For example -1 is the 2nd to last element, or the 1 element after the last element.
  
 
<syntaxhighlight lang="mirc">//echo -a $addtok(A B C D, E, 32)
 
<syntaxhighlight lang="mirc">//echo -a $addtok(A B C D, E, 32)
Line 71: Line 72:
  
 
=== Replacing Tokens ===
 
=== Replacing Tokens ===
To replace a token you can use $puttok and the $reptok. $puttok replaces by the Nth token while $reptok replaces by the token's value.
+
To replace a token you can use $puttok and the $reptok. $puttok replaces by the Nth token while $repltok replaces by the token's value.
 
<syntaxhighlight lang="mirc">var %str = $puttok(<list>, <token>, <Nth_pos>, <code_point>)
 
<syntaxhighlight lang="mirc">var %str = $puttok(<list>, <token>, <Nth_pos>, <code_point>)
 
var %str = $reptok(<list>, <token>, <newToken>, <Nth_pos>, <code_point>)</syntaxhighlight>
 
var %str = $reptok(<list>, <token>, <newToken>, <Nth_pos>, <code_point>)</syntaxhighlight>
Line 120: Line 121:
 
}</syntaxhighlight>
 
}</syntaxhighlight>
  
The script above uses character with the code point of 7 as its delimiter. The script works pretty well for small values (can store as much as 200 items with an average value length of 20 characters or 20 lines with an average of 200 characters per line). Clearly one of the preconditions is that the value cannot contain any characters with a code point value of 7. This example is clearly not suitable for large queues or queues that must execute really fast. (The reason we've used code point 7 is because it's a control character that means bell signal. This makes it one of the least likely characters to be used as a value).
+
The script above uses character with the code point of 7 has its delimiter. The script works pretty well for small values (can store as much as 200 items with an average value length of 20 characters or 20 lines with an average of 200 characters per line). Clearly one of the preconditions is that the value cannot contain any characters with a code point value of 7. This example is clearly not suitable for large queues or queues that must execute really fast. (The reason we've used code point 7 is because it's a control character that means bell signal. This makes it one of the least likely characters to be used as a value).
  
 
== Token Searching/Retrieval ==
 
== Token Searching/Retrieval ==
Line 131: Line 132:
 
;to get the Nth token
 
;to get the Nth token
 
var %tok = $gettok(<list>, <N>, <code_point>)</syntaxhighlight>
 
var %tok = $gettok(<list>, <N>, <code_point>)</syntaxhighlight>
$findtok looks for an exact match while $matchtok looks for a partial match. $wildtok supports {{mirc|wildcard}} characters (? &amp; *) in the substring parameter. They also support 0 for &lt;Nth_pos&gt; to get the total number of matches.
+
$findtok looks for an exact match while $matchtok looks for a partial match. $wildtok supports wildcard characters (? &amp; *) in the substring parameter. They also support 0 for &lt;Nth_pos&gt; to get the total number of matches.
 
<syntaxhighlight lang="mirc">//echo -a $findtok(a a b c d, a, 0, 32)
 
<syntaxhighlight lang="mirc">//echo -a $findtok(a a b c d, a, 0, 32)
 
2
 
2
Line 155: Line 156:
 
The $istok identifier is perhaps the most commonly used identifier in the entire language. It simply returns true or false if the token exists in a list or not.
 
The $istok identifier is perhaps the most commonly used identifier in the entire language. It simply returns true or false if the token exists in a list or not.
  
<syntaxhighlight lang="mirc">var %result = $istok(<list>, <token>, <code_point>)</syntaxhighlight>
+
<syntaxhighlight lang="mirc">var %result = $instok(<list>, <token>, <code_point>)</syntaxhighlight>
  
Another useful feature is the $sorttok identifier which lets you sort the list of tokens numerically, alphabetically, or according to the channel mode prefix. Using r with any of the options will reverse the order.
+
Another useful feature is the $sort identifier which lets you sort the list of tokens numerically, alphabetically, or according to the channel mode prefix. Using r with any of the options will reverse the order.
  
 
<syntaxhighlight lang="mirc">var %result = $sorttok(<list>, <code_point>, <sortingOption>)</syntaxhighlight>
 
<syntaxhighlight lang="mirc">var %result = $sorttok(<list>, <code_point>, <sortingOption>)</syntaxhighlight>
Line 197: Line 198:
 
* $findtok -> $findtokcs
 
* $findtok -> $findtokcs
  
[[Category:mIRC|token manipulation]]
+
[[Category:mIRC]]

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)