# String Manipulation
Core functions for handling string length, substrings, modification, and structure.
## Core Functions
| Function | Method Alias | Description |
| :--- | :--- | :--- |
| `Length(s)` | `.Length` | Returns the number of characters in the string. |
| `SetLength(var s, len)` | `.SetLength(len)` | Resizes the string to `len` characters. |
| `Copy(s, idx [, len])` | `.Copy(idx [, len])` | Returns a substring starting at 1-based `idx`. |
| `Delete(var s, idx, len)` | - | Removes `len` characters from string variable `s`. |
| `Insert(src, var s, idx)` | - | Inserts `src` into string variable `s` at `idx`. |
| `Pos(sub, s [, offset])` | - | Returns 1-based index of first occurrence. |
| `RevPos(sub, s)` | - | Returns 1-based index of last occurrence. |
| `StrFind(s, sub [, from])`| `.IndexOf(sub [, from])`| Returns 1-based index of `sub` in `s`. |
| `StrDeleteLeft(s, n)` | `.DeleteLeft(n)` | Deletes `n` characters from the left. |
| `StrDeleteRight(s, n)` | `.DeleteRight(n)` | Deletes `n` characters from the right. |
| `StrContains(s, sub)` | `.Contains(sub)` | True if `sub` is present in `s`. |
| `StrBeginsWith(s, sub)` | `.StartsWith(sub)` | True if `s` starts with `sub`. |
| `StrEndsWith(s, sub)` | `.EndsWith(sub)` | True if `s` ends with `sub`. |
| `StrCount(sub, s)` | `.Count(sub)` | Returns number of occurrences of `sub` in `s`. |
| `StrMatches(s, mask)` | `.Matches(mask)` | Wildcard matching (`*` and `?`). |
## Substrings and Slicing
These functions simplify extracting parts of a string relative to a delimiter.
| Function | Method Alias | Description |
| :--- | :--- | :--- |
| `StrBefore(s, delim)` | `.Before(delim)` | Text before the first occurrence of `delim`. |
| `StrBeforeLast(s, delim)` | `.BeforeLast(delim)` | Text before the last occurrence of `delim`. |
| `StrAfter(s, delim)` | `.After(delim)` | Text after the first occurrence of `delim`. |
| `StrAfterLast(s, delim)` | `.AfterLast(delim)` | Text after the last occurrence of `delim`. |
| `StrBetween(s, start, stop)`| `.Between(start, stop)`| Text between `start` and `stop` delimiters. |
| `LeftStr(s, count)` | `.Left(count)` | Returns the first `count` characters. |
| `RightStr(s, count)` | `.Right(count)` | Returns the last `count` characters. |
| `MidStr(s, start, len)`| `.SubString(start, len)` | Returns `len` characters from `start`. |
| `SubStr(s, start, len)`| - | Alias for `MidStr`. |
| `SubString(s, start, end)` | - | Text from `start` to `end` (exclusive of end). **Note:** The method `.SubString` is an alias for `MidStr` (uses length), not this function. |
:::info
### Related Reference
For type conversions (like `FloatToStr`, `IntToStr`) and case transformations, see **[String Transformation](/ref/strings_transform)**.
:::
## Splitting and Joining
| Function | Method Alias | Description |
| :--- | :--- | :--- |
| `StrSplit(s, delim)` | `.Split(delim)` | Splits string into an `array of String`. |
| `StrJoin(arr, delim)` | `.Join(delim)` | Joins an array into a single string. |
| `StrArrayPack(arr)` | `.Pack` | Removes empty strings from an array. |
```pascal
var csv := 'apple,banana,cherry';
var fruits := csv.Split(',');
var joined := fruits.Join('; ');
PrintLn(joined);
// OUTPUT
// apple; banana; cherry
```
## Deleting Substrings
```pascal
var s := '--- Content starts here ---';
// Delete multiple characters from the left
var content := s.DeleteLeft(4);
PrintLn('DeleteLeft(4): ' + content);
// Delete multiple characters from the right
var trimmed := content.DeleteRight(4);
PrintLn('DeleteRight(4): ' + trimmed);
// Using functional style
PrintLn('Functional: ' + StrDeleteLeft('banana', 2));
// OUTPUT
// DeleteLeft(4): Content starts here ---
// DeleteRight(4): Content starts here
// Functional: nana
```
String Manipulation
Core functions for handling string length, substrings, modification, and structure.
Core Functions
Function
Method Alias
Description
Length(s)
.Length
Returns the number of characters in the string.
SetLength(var s, len)
.SetLength(len)
Resizes the string to len characters.
Copy(s, idx [, len])
.Copy(idx [, len])
Returns a substring starting at 1-based idx.
Delete(var s, idx, len)
-
Removes len characters from string variable s.
Insert(src, var s, idx)
-
Inserts src into string variable s at idx.
Pos(sub, s [, offset])
-
Returns 1-based index of first occurrence.
RevPos(sub, s)
-
Returns 1-based index of last occurrence.
StrFind(s, sub [, from])
.IndexOf(sub [, from])
Returns 1-based index of sub in s.
StrDeleteLeft(s, n)
.DeleteLeft(n)
Deletes n characters from the left.
StrDeleteRight(s, n)
.DeleteRight(n)
Deletes n characters from the right.
StrContains(s, sub)
.Contains(sub)
True if sub is present in s.
StrBeginsWith(s, sub)
.StartsWith(sub)
True if s starts with sub.
StrEndsWith(s, sub)
.EndsWith(sub)
True if s ends with sub.
StrCount(sub, s)
.Count(sub)
Returns number of occurrences of sub in s.
StrMatches(s, mask)
.Matches(mask)
Wildcard matching (* and ?).
Substrings and Slicing
These functions simplify extracting parts of a string relative to a delimiter.
Function
Method Alias
Description
StrBefore(s, delim)
.Before(delim)
Text before the first occurrence of delim.
StrBeforeLast(s, delim)
.BeforeLast(delim)
Text before the last occurrence of delim.
StrAfter(s, delim)
.After(delim)
Text after the first occurrence of delim.
StrAfterLast(s, delim)
.AfterLast(delim)
Text after the last occurrence of delim.
StrBetween(s, start, stop)
.Between(start, stop)
Text between start and stop delimiters.
LeftStr(s, count)
.Left(count)
Returns the first count characters.
RightStr(s, count)
.Right(count)
Returns the last count characters.
MidStr(s, start, len)
.SubString(start, len)
Returns len characters from start.
SubStr(s, start, len)
-
Alias for MidStr.
SubString(s, start, end)
-
Text from start to end (exclusive of end). Note: The method .SubString is an alias for MidStr (uses length), not this function.
Related Reference
For type conversions (like FloatToStr, IntToStr) and case transformations, see String Transformation.
Splitting and Joining
Function
Method Alias
Description
StrSplit(s, delim)
.Split(delim)
Splits string into an array of String.
StrJoin(arr, delim)
.Join(delim)
Joins an array into a single string.
StrArrayPack(arr)
.Pack
Removes empty strings from an array.
var csv :='apple,banana,cherry';var fruits := csv.Split(',');var joined := fruits.Join('; ');
PrintLn(joined);
Result
apple; banana; cherry
Deleting Substrings
var s :='--- Content starts here ---';// Delete multiple characters from the leftvar content := s.DeleteLeft(4);
PrintLn('DeleteLeft(4): '+ content);// Delete multiple characters from the rightvar trimmed := content.DeleteRight(4);
PrintLn('DeleteRight(4): '+ trimmed);// Using functional style
PrintLn('Functional: '+ StrDeleteLeft('banana',2));
Result
DeleteLeft(4): Content starts here ---
DeleteRight(4): Content starts here
Functional: nana