> For the complete documentation index, see [llms.txt](https://php-fhir-tools.ardenexal.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://php-fhir-tools.ardenexal.net/fhirpath/functions/string.md).

# String

String functions operate on a single-item String input unless noted otherwise.

| Function                              | Description                                                           | Example                                 |
| ------------------------------------- | --------------------------------------------------------------------- | --------------------------------------- |
| `substring(start [, length])`         | Returns the substring from `start` (0-based) for `length` characters. | `'abcdef'.substring(0, 3)` → `'abc'`    |
| `length()`                            | Returns the character count as an Integer.                            | `'abc'.length()` → `3`                  |
| `startsWith(prefix)`                  | True when the string begins with `prefix`.                            | `'abc'.startsWith('ab')`                |
| `endsWith(suffix)`                    | True when the string ends with `suffix`.                              | `'abc'.endsWith('bc')`                  |
| `contains(substring)`                 | True when the string contains `substring`.                            | `'abc'.contains('b')`                   |
| `indexOf(substring)`                  | 0-based index of the first match, or `-1`.                            | `'abc'.indexOf('b')` → `1`              |
| `upper()`                             | Converts to upper case.                                               | `'abc'.upper()` → `'ABC'`               |
| `lower()`                             | Converts to lower case.                                               | `'ABC'.lower()` → `'abc'`               |
| `replace(pattern, substitution)`      | Replaces all plain-string occurrences of `pattern`.                   | `'abc'.replace('b', 'x')` → `'axc'`     |
| `replaceMatches(regex, substitution)` | Regex-based replace.                                                  | `'abc123'.replaceMatches('[0-9]', 'x')` |
| `matches(regex)`                      | True when the regex matches anywhere in the string.                   | `'abc'.matches('[a-z]+')`               |
| `matchesFull(regex)`                  | True when the regex matches the entire string.                        | `'abc'.matchesFull('[a-z]+')`           |
| `trim()`                              | Removes leading and trailing whitespace.                              | `' abc '.trim()` → `'abc'`              |
| `split(separator)`                    | Splits the string into a collection.                                  | `'a,b,c'.split(',')`                    |
| `toChars()`                           | Splits the string into a collection of single characters.             | `'abc'.toChars()`                       |
| `join([separator])`                   | Joins a collection of strings into one string.                        | `('a' \| 'b').join(',')` → `'a,b'`      |
| `encode(format)`                      | Encodes a string (`hex`, `base64`, `urlbase64`).                      | `'abc'.encode('base64')`                |
| `decode(format)`                      | Decodes a string using the given format.                              | `'YWJj'.decode('base64')` → `'abc'`     |
| `escape(target)`                      | Escapes a string for `html` or `json`.                                | `'<a>'.escape('html')`                  |
| `unescape(target)`                    | Reverses `escape()` for `html` or `json`.                             | `'&lt;a&gt;'.unescape('html')`          |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://php-fhir-tools.ardenexal.net/fhirpath/functions/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.
