Strings
The String type (string) represents an arbitrary byte sequence or series of Unicode (UTF-8) characters. It is the most common type in iXML because all XML content is inherently textual.
- Neutral literal:
''(empty string) - typeof result:
'string'
Strings are the default
Every <set> operation produces a string, regardless of what the content looks like:
<set var="x">42</set>
<typeof var="x" var_result="t" />
<output>$t</output>
<!-- string -->
Even though 42 looks like a number, it is stored as the string "42". To get an integer, use cast:
<set var="x">42</set>
<cast var="x" type="int" />
Common string operations
iXML provides a comprehensive set of string manipulation commands:
| Task | Command | Example |
|---|---|---|
| Get length | length | <length var="len">$str</length> |
| Concatenate | concat | <concat var="result" glue=", ">$arr</concat> |
| Lowercase | tolower | <tolower var="str">$str</tolower> |
| Uppercase | toupper | <toupper var="str">$str</toupper> |
| Trim whitespace | trim | <trim var="str">$str</trim> |
| Find position | pos | <pos var="p" haystack="$str">needle</pos> |
| Extract substring | substr | <substr var="part" from="0" length="5">$str</substr> |
| Pad string | pad | <pad var="str" length="10" char="0" align="right">$str</pad> |
| Regex match | match | <match var="m" pattern="/\d+/">$str</match> |
| Regex replace | replace | <replace var="str" pattern="/\s+/" replacement=" ">$str</replace> |
| Split to array | split | <split var="parts" delimiter=",">$str</split> |
String in comparisons
An empty string ('') is considered "falsy" — it compares equal to NULL, FALSE, and undefined in loose comparison:
<set var="x"></set>
<if value1="$x" func="=" value2="">
<output>x is empty</output>
</if>
A non-empty string (even "0") is truthy in boolean context, except when compared numerically. See Type Conversion for the full comparison table.
Encoding and escaping
For encoding/decoding strings (Base64, URL encoding, HTML escaping, JSON, etc.), see the Standard Library: Encoding chapter.