Skip to content

string

A string is an array of characters. In MQ2 there is no single character datatype, so any variable or expression that contains text is considered a string.

Members

| string | Arg[#,s] | Returns the #th argument of the string separated by s. The separator s must be a single character (defaults to space).
See [Difference between Arg and Token][1].

[int][int] Compare[text]

Determines how the initial string and the second string, text, compare to each other:
  • If both are the same, Compare will return 0.
  • If the string is alphabetically before text, Compare will return -1.
  • If text is alphabetically after string, Compare will return 1.
Compare is case-insensitive

[int][int] CompareCS[text]

The same as Compare, except that it is case-sensitive

[int][int] Count[c]

Returns how many times a single character c occurs in the string

bool Equal[text]

If the initial string and the second string text are exactly the same, returns TRUE.
Equal is case-insensitive

bool EqualCS[text]

The same as Equal, except that it is case-sensitive

[int][int] Find[text]

This tries to find the second string text within the original string:
  • If it is successful, it returns the first position in the string where text begins.
  • It returns NULL if text is not found.
Find is case-insensitive

string Left[#]

Returns the first # characters of the string. A negative # will return the whole string except for the last # characters

[int][int] Length

Returns the length of the string as an integer

string Lower

Returns the string in all lower-case

string Mid[p,n]

Returns a segment of the string, starting at position p and running n characters.

bool NotEqual[text]

If the initial string and the second string text are exactly the same, returns FALSE. NotEqual is case-insensitive

bool NotEqualCS[text]

The same as NotEqual, except that it is case-sensitive.

string Replace[ReplaceThis,WithThis]

Replaces ReplaceThis with WithThis.

string Right[#]

Returns the last # characters of the string. A negative # will return the whole string except for the first # characters
Returns the plain text version of a string, stripping out the links

string Token[#,s]

Returns the #th token of the string separated by s. The separator s must be a single character (defaults to space).
See [Difference between Arg and Token][1].

string Upper

Returns the string in all upper-case

string (To String)

Returns the string

Usage

Simple Examples

/declare TestString abcdebc
/echo ${TestString.Find[bc]}         | Will return 2
/echo ${TestString.Left[2]}          | Will return "ab"
/echo ${TestString.Left[-2]}         | Will return "abcde"
/echo ${TestString.Mid[2,3]}         | Will return "bcd"
/echo ${TestString.Right[2]}         | Will return "bc"
/echo ${TestString.Right[-2]}        | Will return "cdebc"

Difference between Arg and Token

Arg[#,s] and Token[#,s] are very similar. The only difference between them is Token will include null values, while Arg will skip them. For example:

/declare TestString ABC,,DEF

| Will return "DEF" because it is the second non-null string separated by a comma:
/echo ${TestString.Arg[2,,]}

| Will return "NULL" because the second token, the null string, is not ignored:
/echo ${TestString.Token[2,,]}

Compare strings to strings

Warning

There is a temptation by some novice macro writers to put the string inside quotes within brackets. Don't!

#Event SpellWornOff  "Your #1# spell has worn off of #2#."

Sub Event_SpellWornOff(string Line, string SpellName, string OnWho) 
   | You can put all kinds of logic here, on what to do when certain 
   | buffs or debuffs wear off.
   | In this example, we'll just check to see if the spell that wore
   | off is a particular spell multiple words seperated by spaces.
   |
   | Note: No quotes inside the brackets, and pay attention
   | to where the curly brackets are in the /if compare statement.
   /echo SpellWornOff: ${SpellName} wore off ${OnWho}
   /if (${SpellName.Equal[Enveloping Roots]}) /echo Yikes, Root wore off ... run!
/return

[1]: #difference-between-arg-and-token[int]: datatype-int.md