# Text.Split

> The C# string.Split: breaks a string on a separator and returns the substrings as a List<string> — iterable with foreach and queryable with .Count / .Contains. Empty segments are kept, exactly like C#'s StringSplitOptions.None. Runs in memory only.

<!-- id: function-text-split · area: function · stability: stable · html: https://osysharp.com/reference/function/text-split/ -->

## Summary        {#summary}
`Text.Split(s, separator)` splits `s` on each occurrence of `separator` and returns the substrings as a
**`List<string>`** — the mutable-list shape, so the result is iterable with `foreach` and supports
`.Count` and `.Contains`. This is the inverse of `string.Join`, and mirrors C#'s
`string.Split(separator)` with `StringSplitOptions.None`: **empty segments are kept**.

## Signature      {#signature}
```osy syntax
Text.Split(<string> s, <string> separator) -> List<string>
```

## Description    {#description}
The result is a real `List<string>` (not a read-only query result), so the collection surface applies:
`foreach`, `.Count`, `.Contains`, and passing it to `string.Join`. Membership and iteration are the
idiomatic ways to consume it.

Empty handling is **C#-faithful (`StringSplitOptions.None`)**: `Text.Split("a,,b", ",")` yields three
elements `["a", "", "b"]`, and `Text.Split("", ",")` yields a single empty element `[""]`.

`Text.Split` is **in-memory only** — a split produces a set, which has no SQL push-down form, so it is
called on locals inside a function body, never inside a query predicate.

## Examples       {#examples}
```osy title="trim each CSV field" test app=text-search
List<string> TrimFields(string csv) {
  var trimmed = new List<string>();
  foreach (var field in Text.Split(csv, ",")) {
    trimmed.Add(Text.Trim(field));
  }
  return trimmed;
}
// TrimFields("orders, customers , items")  ->  ["orders", "customers", "items"]
```

## See also       {#see-also}
- [String interpolation & format specifiers](https://osysharp.com/reference/function/string-interpolation/) — `string.Join` is the inverse (list → string)
- [Text.LastIndexOf](https://osysharp.com/reference/function/text-lastindexof/) — the other in-memory-only string builtin
