Skip to content

Latest commit

 

History

History
183 lines (132 loc) · 6.63 KB

File metadata and controls

183 lines (132 loc) · 6.63 KB
tags
datatype

string

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

Members

{{ renderMember(type='string', name='Arg', params='#,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.

{{ renderMember(type='int', name='Compare', params='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

{{ renderMember(type='int', name='CompareCS', params='text') }}

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

{{ renderMember(type='int', name='Count', params='c') }}

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

{{ renderMember(type='bool', name='Equal', params='text') }}

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

{{ renderMember(type='bool', name='EqualCS', params='text') }}

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

{{ renderMember(type='int', name='Find', params='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

{{ renderMember(type='string', name='Left', params='#') }}

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

{{ renderMember(type='int', name='Length') }}

: Returns the length of the string as an integer

{{ renderMember(type='string', name='Lower') }}

: Returns the string in all lower-case

{{ renderMember(type='string', name='Mid', params='p,n') }}

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

{{ renderMember(type='bool', name='NotEqual', params='text') }}

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

{{ renderMember(type='bool', name='NotEqualCS', params='text') }}

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

{{ renderMember(type='string', name='Replace', params='ReplaceThis,WithThis') }}

: Replaces ReplaceThis with WithThis.

{{ renderMember(type='string', name='Right', params='#') }}

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

{{ renderMember(type='string', name='StripLinks') }}

: Returns the plain text version of a string, stripping out the links

{{ renderMember(type='string', name='Token', params='#,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.

{{ renderMember(type='string', name='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