# DataType: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

| **Type**                                                                                                     | **Member**                                                     | **Description**                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \<em>\</em>[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\<em>\</em> | **Arg\[**#**,**&#x73;**]**                                     | <p>Returns the #th argument of the string separated by <em>s</em>. The separator <em>s</em> must be a single character (defaults to space).<br>See below for difference between <strong>Token</strong> and <strong>Arg</strong></p>                                                                                                                                                                                           |
| [*int*](/macroquest/data-types-and-top-level-objects/data-types/datatype-int.md)                             | **Compare\[**&#x74;ex&#x74;**]**                               | <p>Determines how the initial string and the second string, <em>text</em>, compare to each other:</p><ul><li>If both are the same, <strong>Compare</strong> will return 0.</li><li>If the string is alphabetically before text, <strong>Compare</strong> will return -1.</li><li>If text is alphabetically after string, <strong>Compare</strong> will return 1.</li></ul><p><strong>Compare</strong> is case-insensitive</p> |
| [*int*](/macroquest/data-types-and-top-level-objects/data-types/datatype-int.md)                             | **CompareCS\[**&#x74;ex&#x74;**]**                             | CompareCS is exactly the same as **Compare**, except that it is case-sensitive                                                                                                                                                                                                                                                                                                                                                |
| [*int*](/macroquest/data-types-and-top-level-objects/data-types/datatype-int.md)                             | **Count\[**&#x63;**]**                                         | Returns how many times a single character *c* occurs in the string                                                                                                                                                                                                                                                                                                                                                            |
| [*bool*](/macroquest/data-types-and-top-level-objects/data-types/datatype-bool.md)                           | **Equal\[**&#x74;ex&#x74;**]**                                 | If the initial string and the second string *text* are exactly the same, returns TRUE. **Equal** is case-insensitive                                                                                                                                                                                                                                                                                                          |
| [*bool*](/macroquest/data-types-and-top-level-objects/data-types/datatype-bool.md)                           | **EqualCS\[**&#x74;ex&#x74;**]**                               | **EqualCS** is exactly the same as **Equal**, except that it is case-sensitive                                                                                                                                                                                                                                                                                                                                                |
| [*int*](/macroquest/data-types-and-top-level-objects/data-types/datatype-int.md)                             | **Find\[**&#x74;ex&#x74;**]**                                  | <p>This tries to find the second string <em>text</em> within the original string:</p><ul><li>If it is successful, it returns the first position in the string where <em>text</em> begins.</li><li>It returns NULL if <em>text</em> is not found.</li></ul><p><strong>Find</strong> is case-insensitive</p>                                                                                                                    |
| [*int*](/macroquest/data-types-and-top-level-objects/data-types/datatype-int.md)                             | **Length**                                                     | Returns the length of the string as an integer                                                                                                                                                                                                                                                                                                                                                                                |
| \<em>\</em>[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\<em>\</em> | **Left\[**#**]**                                               | Returns the first # characters of the string. A negative # will return the whole string except for the last # characters                                                                                                                                                                                                                                                                                                      |
| \<em>\</em>[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\<em>\</em> | **Lower**                                                      | Returns the string in all lower-case                                                                                                                                                                                                                                                                                                                                                                                          |
| \<em>\</em>[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\<em>\</em> | **Mid\[**&#x70;**,**&#x6E;**]**                                | Returns a segment of the string, starting at position **p** and running **n** characters                                                                                                                                                                                                                                                                                                                                      |
| [*bool*](/macroquest/data-types-and-top-level-objects/data-types/datatype-bool.md)                           | **NotEqual\[**&#x74;ex&#x74;**]**                              | If the initial string and the second string *text* are exactly the same, returns FALSE. **NotEqual** is case-insensitive                                                                                                                                                                                                                                                                                                      |
| [*bool*](/macroquest/data-types-and-top-level-objects/data-types/datatype-bool.md)                           | **NotEqualCS\[**&#x74;ex&#x74;**]**                            | **NotEqualCS** is exactly the same as **NotEqual**, except that it is case-sensitive                                                                                                                                                                                                                                                                                                                                          |
| \<em>\</em>[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\<em>\</em> | **Replace\[**&#x52;eplaceThi&#x73;**,**&#x57;ithThi&#x73;**]** | Replaces *ReplaceThis* with *WithThis*                                                                                                                                                                                                                                                                                                                                                                                        |
| \<em>\</em>[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\<em>\</em> | **Right\[**#**]**                                              | Returns the last # characters of the string. A negative # will return the whole string except for the first # characters                                                                                                                                                                                                                                                                                                      |
| \<em>\</em>[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\<em>\</em> | **Token\[**#**,**&#x73;**]**                                   | <p>Returns the #th token of the string separated by <em>s</em>. The separator <em>s</em> must be a single character (defaults to space).<br>See below for difference between <strong>Arg</strong> and <strong>Token</strong></p>                                                                                                                                                                                              |
| \<em>\</em>[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\<em>\</em> | **Upper**                                                      | Returns the string in all upper-case                                                                                                                                                                                                                                                                                                                                                                                          |
| \<em>\</em>[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\<em>\</em> | **To String**                                                  | This is a string!                                                                                                                                                                                                                                                                                                                                                                                                             |

## Examples

### 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
/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
```

### 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://macroquest.gitbook.io/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
