# String Transformation
Functions for converting case, encoding, escaping, and type conversion.
## Transformation
| Function | Method Alias | Description |
| :--- | :--- | :--- |
| `LowerCase(s)` | `.ToLower` / `.LowerCase` | Converts to lowercase (Unicode). |
| `ASCIILowerCase(s)` | - | Converts to lowercase (ASCII only). |
| `UpperCase(s)` | `.ToUpper` / `.UpperCase` | Converts to uppercase (Unicode). |
| `ASCIIUpperCase(s)` | - | Converts to uppercase (ASCII only). |
| `Trim(s)` | `.Trim` | Removes whitespace from both ends. |
| `Trim(s, L, R)` | `.Trim(L, R)` | Removes `L` chars from left and `R` from right. |
| `TrimLeft(s) / TrimRight(s)`| `.TrimLeft / .TrimRight`| Removes whitespace from one end. |
| `PadLeft(s, len [, ch])` | `.PadLeft(len [, ch])` | Pads string to `len` with character `ch`. |
| `PadRight(s, len [, ch])` | `.PadRight(len [, ch])` | Pads string to `len` with character `ch`. |
| `StrReplace(s, old, new)` | `.Replace(old, new)` | Replaces all occurrences of `old` with `new`. |
| `ReverseString(s)` | `.Reverse` | Reverses the character order. |
| `DupeString(s, count)` | `.Dupe(count)` | Returns the string repeated `count` times. |
| `NormalizeString(s)` | `.Normalize` | Normalizes Unicode string (NFC default). |
| `StripAccents(s)` | `.StripAccents` | Removes diacritics (e.g. é -> e). |
## Conversion
| Function | Method Alias | Description |
| :--- | :--- | :--- |
| `IntToHex(v, digits)` | `.ToHexString(digits)` | Integer to hexadecimal string. |
| `IntToBin(v, digits)` | `.ToBinaryString(digits)` | Integer to binary string. |
| `HexToInt(s)` | `.HexToInteger` | Hexadecimal string to integer. |
| `FloatToStr(f [, p])` | `.ToString` | Float to string (optional precision `p`). |
| `ByteSizeToStr(v)` | - | Converts a number of bytes into human-readable size (e.g. "1.5 MB"). |
| `BoolToStr(b)` | `.ToString` | Boolean to "True" or "False". |
| `StrToBool(s)` | `.ToBoolean` | String to boolean. |
## Encoding and Escaping
| Function | Method Alias | Description |
| :--- | :--- | :--- |
| `StrToHtml(s)` | `.ToHtml` | HTML entity encoding. |
| `StrToHtmlAttribute(s)` | `.ToHtmlAttribute` | HTML attribute encoding. |
| `StrToJSON(s)` | `.ToJSON` | Escapes string for JSON/JavaScript literal. |
| `StrToCSSText(s)` | `.ToCSSText` | Escapes string for CSS content. |
| `StrToXML(s)` | `.ToXML` | XML text encoding. |
| `QuotedStr(s [, quote])` | `.QuotedString` | Wraps string in quotes (default `'`). |
| `NormalizeString(s [, form])` | `.Normalize` | Unicode normalization (NFC, NFD, etc). |
| `StrIsASCII(s)` | `.IsASCII` | Returns True if all characters in the string are ASCII (0..127). |
## Advanced Transformations
```pascal
// Specialized Trimming
var s := "[[[Hello]]]";
PrintLn('Trim(3, 3): ' + s.Trim(3, 3));
// Array Packing (on dynamic array)
var arr : array of String = ['A', '', 'B', ' ', 'C'];
var packed := arr.Pack();
PrintLn('Packed: ' + packed.Join(', '));
// Unicode Normalization
var accented := 'e'#$0301; // e + combining acute accent
PrintLn('Length pre-normalize: ' + accented.Length.ToString);
var normalized := accented.Normalize();
PrintLn('Length post-normalize: ' + normalized.Length.ToString);
// OUTPUT
// Trim(3, 3): Hello
// Packed: A, B, , C
// Length pre-normalize: 2
// Length post-normalize: 1
```
String Transformation
Functions for converting case, encoding, escaping, and type conversion.
| Function |
Method Alias |
Description |
LowerCase(s) |
.ToLower / .LowerCase |
Converts to lowercase (Unicode). |
ASCIILowerCase(s) |
- |
Converts to lowercase (ASCII only). |
UpperCase(s) |
.ToUpper / .UpperCase |
Converts to uppercase (Unicode). |
ASCIIUpperCase(s) |
- |
Converts to uppercase (ASCII only). |
Trim(s) |
.Trim |
Removes whitespace from both ends. |
Trim(s, L, R) |
.Trim(L, R) |
Removes L chars from left and R from right. |
TrimLeft(s) / TrimRight(s) |
.TrimLeft / .TrimRight |
Removes whitespace from one end. |
PadLeft(s, len [, ch]) |
.PadLeft(len [, ch]) |
Pads string to len with character ch. |
PadRight(s, len [, ch]) |
.PadRight(len [, ch]) |
Pads string to len with character ch. |
StrReplace(s, old, new) |
.Replace(old, new) |
Replaces all occurrences of old with new. |
ReverseString(s) |
.Reverse |
Reverses the character order. |
DupeString(s, count) |
.Dupe(count) |
Returns the string repeated count times. |
NormalizeString(s) |
.Normalize |
Normalizes Unicode string (NFC default). |
StripAccents(s) |
.StripAccents |
Removes diacritics (e.g. é -> e). |
| Function |
Method Alias |
Description |
IntToHex(v, digits) |
.ToHexString(digits) |
Integer to hexadecimal string. |
IntToBin(v, digits) |
.ToBinaryString(digits) |
Integer to binary string. |
HexToInt(s) |
.HexToInteger |
Hexadecimal string to integer. |
FloatToStr(f [, p]) |
.ToString |
Float to string (optional precision p). |
ByteSizeToStr(v) |
- |
Converts a number of bytes into human-readable size (e.g. "1.5 MB"). |
BoolToStr(b) |
.ToString |
Boolean to "True" or "False". |
StrToBool(s) |
.ToBoolean |
String to boolean. |
| Function |
Method Alias |
Description |
StrToHtml(s) |
.ToHtml |
HTML entity encoding. |
StrToHtmlAttribute(s) |
.ToHtmlAttribute |
HTML attribute encoding. |
StrToJSON(s) |
.ToJSON |
Escapes string for JSON/JavaScript literal. |
StrToCSSText(s) |
.ToCSSText |
Escapes string for CSS content. |
StrToXML(s) |
.ToXML |
XML text encoding. |
QuotedStr(s [, quote]) |
.QuotedString |
Wraps string in quotes (default '). |
NormalizeString(s [, form]) |
.Normalize |
Unicode normalization (NFC, NFD, etc). |
StrIsASCII(s) |
.IsASCII |
Returns True if all characters in the string are ASCII (0..127). |
var s := "[[[Hello]]]";
PrintLn('Trim(3, 3): ' + s.Trim(3, 3));
var arr : array of String = ['A', '', 'B', ' ', 'C'];
var packed := arr.Pack();
PrintLn('Packed: ' + packed.Join(', '));
var accented := 'e'#$0301;
PrintLn('Length pre-normalize: ' + accented.Length.ToString);
var normalized := accented.Normalize();
PrintLn('Length post-normalize: ' + normalized.Length.ToString);
Result
Trim(3, 3): Hello
Packed: A, B, , C
Length pre-normalize: 2
Length post-normalize: 1