DataType:string
From MacroQuest Wiki
Contents |
[edit]
Description
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.
[edit]
Members
| Type | Member | Description |
| 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 below for difference between Token and Arg |
| int | Compare[text] | Determines how the initial string and the second string, text, compare to each other:
|
| int | CompareCS[text] | CompareCS is exactly the same as Compare, except that it is case-sensitive |
| 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] | EqualCS is exactly the same as Equal, except that it is case-sensitive |
| int | Find[text] | This tries to find the second string text within the original string:
|
| int | Length | Returns the length of the string as an integer |
| string | Left[#] | Returns the first # characters of the string. A negative # will return the whole string except for the last # characters |
| 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] | NotEqualCS is exactly 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 |
| 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 below for difference between Arg and Token |
| string | Upper | Returns the string in all upper-case |
| string | To String | This is a string! |
[edit]
Examples
[edit]
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"
[edit]
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
/echo ${TestString.Arg[2,,]} Will return "DEF" because it is the second non-null string separated by a comma
/echo ${TestString.Token[2,,]} Will return "NULL" because the second token, the null string, is not ignored
[edit]
Compare strings to strings
- There is a temptation by some novice MQ2 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
[edit]
