Zum Hauptinhalt springen

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:

XML
<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:

XML
<set var="x">42</set>
<cast var="x" type="int" />

Common string operations

iXML provides a comprehensive set of string manipulation commands:

TaskCommandExample
Get lengthlength<length var="len">$str</length>
Concatenateconcat<concat var="result" glue=", ">$arr</concat>
Lowercasetolower<tolower var="str">$str</tolower>
Uppercasetoupper<toupper var="str">$str</toupper>
Trim whitespacetrim<trim var="str">$str</trim>
Find positionpos<pos var="p" haystack="$str">needle</pos>
Extract substringsubstr<substr var="part" from="0" length="5">$str</substr>
Pad stringpad<pad var="str" length="10" char="0" align="right">$str</pad>
Regex matchmatch<match var="m" pattern="/\d+/">$str</match>
Regex replacereplace<replace var="str" pattern="/\s+/" replacement=" ">$str</replace>
Split to arraysplit<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:

XML
<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.