# Strings

Strings in RuLA represent text values. They are enclosed in double quotes.

## Creating Strings

Create a string by enclosing text in double quotes:

```
"Hello World"
"Customer Name"
""
```

An empty string (`""`) is valid and represents a string with no characters.

## String Manipulation

### Concatenation

Join strings together using `+` or `CONCAT`:

```
"Hello" + " " + "World"     # Results in "Hello World"
CONCAT("Hello", " World")   # Results in "Hello World"
```

### Accessing Characters

Access individual characters by index (0-based):

```
"Hello"[0]      # Returns "H"
"Hello"[4]      # Returns "o"
```

### Slicing

Extract a portion of a string:

```
SLICE("Hello World", 0, 5)     # Returns "Hello"
LEFT("Hello World", 5)         # Returns "Hello"
RIGHT("Hello World", 5)        # Returns "World"
```

### Case Conversion

```
LOWER("Hello World")           # Returns "hello world"
UPPER("Hello World")           # Returns "HELLO WORLD"
```

### Trimming Whitespace

```
TRIM("  hello  ")              # Returns "hello"
TRIM_LEFT("  hello")           # Returns "hello"
```

## Useful String Functions

| Function                                                                      | Description                       | Example                                  |
| ----------------------------------------------------------------------------- | --------------------------------- | ---------------------------------------- |
| [`LEN`](/rule-language/operators/string-operators/len.md)                     | Returns the number of characters  | `LEN("abc")` → `3`                       |
| [`CONCAT`](/rule-language/operators/string-operators/concat.md)               | Joins multiple strings            | `CONCAT("a", "b")` → `"ab"`              |
| [`LOWER`](/rule-language/operators/string-operators/lower.md)                 | Converts to lowercase             | `LOWER("ABC")` → `"abc"`                 |
| [`UPPER`](/rule-language/operators/string-operators/upper.md)                 | Converts to uppercase             | `UPPER("abc")` → `"ABC"`                 |
| [`TRIM`](/rule-language/operators/string-operators/trim.md)                   | Removes whitespace from both ends | `TRIM(" a ")` → `"a"`                    |
| [`LEFT`](/rule-language/operators/string-operators/left.md)                   | First n characters                | `LEFT("hello", 2)` → `"he"`              |
| [`RIGHT`](/rule-language/operators/string-operators/right.md)                 | Last n characters                 | `RIGHT("hello", 2)` → `"lo"`             |
| [`SLICE`](/rule-language/operators/string-operators/slice.md)                 | Extract substring                 | `SLICE("hello", 1, 3)` → `"el"`          |
| [`REPLACE`](/rule-language/operators/string-operators/replace.md)             | Replace occurrences               | `REPLACE("a-b", "-", "/")` → `"a/b"`     |
| [`SPLIT`](/rule-language/operators/string-operators/split.md)                 | Split into list                   | `SPLIT("a,b", ",")` → `["a", "b"]`       |
| [`STARTS_WITH`](/rule-language/operators/string-operators/starts_with.md)     | Check prefix                      | `STARTS_WITH("abc", "ab")` → `True`      |
| [`ENDS_WITH`](/rule-language/operators/string-operators/ends_with.md)         | Check suffix                      | `ENDS_WITH("abc", "bc")` → `True`        |
| [`JOIN`](/rule-language/operators/string-operators/join.md)                   | Join list into string             | `JOIN(["a", "b"], "-")` → `"a-b"`        |
| [`FORMAT_NUMBER`](/rule-language/operators/string-operators/format_number.md) | Format as string                  | `FORMAT_NUMBER(3.14159, 2)` → `"3.14"`   |
| [`LEVENSHTEIN`](/rule-language/operators/string-operators/levenshtein.md)     | Edit distance                     | `LEVENSHTEIN("kitten", "sitting")` → `3` |
| [`PAD_LEFT`](/rule-language/operators/string-operators/pad_left.md)           | Pad on left                       | `PAD_LEFT("5", 3, "0")` → `"005"`        |
| [`PAD_RIGHT`](/rule-language/operators/string-operators/pad_right.md)         | Pad on right                      | `PAD_RIGHT("5", 3, "0")` → `"500"`       |
| [`TRIM_LEFT`](/rule-language/operators/string-operators/trim_left.md)         | Removes whitespace from start     | `TRIM_LEFT(" hello")` → `"hello"`        |

## String Comparison

Compare strings using standard operators:

```
"abc" = "abc"           # True (exact match)
"abc" != "def"          # True
"abc" contains "b"      # True
"abc" matches "a.*c"    # True (regex match)
```


---

# 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://docs.atfinity.io/rule-language/data-types/strings.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.
