# Strings module

The **Strings** module groups together the runtime's text-processing primitives --- measuring strings, looking inside them, building new ones from old ones, splitting and joining arrays of them, and formatting non-string values as text. Most members come in two callable forms: a `$`-suffixed form (e.g. **Left$**) that returns a **String**, and an unsuffixed form (e.g. **Left**) that returns a **Variant** (**String**) and propagates **Null** through the call. Several also have a `B` variant --- **AscB**, **ChrB**, **InStrB**, **LeftB**, **LenB**, **MidB**, **RightB** --- that operates on byte positions rather than character positions, for use with byte-buffer data held in a **String**.

## Length and character codes

[**Len**](/tB/Modules/Strings/Len.md) returns the number of characters in a string, or --- when given a non-string variable --- the number of bytes the variable occupies. [**Asc**](/tB/Modules/Strings/Asc.md) returns the character code of a string's first character; [**Chr**](/tB/Modules/Strings/Chr.md) is its inverse, building a single-character string from a code point. The `W` variants ([**AscW**](/tB/Modules/Strings/Asc.md), [**ChrW**](/tB/Modules/Strings/Chr.md)) work in Unicode regardless of the system code page.

```tb check_build
Debug.Print Len("Hello")            ' 5
Debug.Print Asc("A")                ' 65
Debug.Print Chr(65)                 ' "A"
```

## Searching and comparing

[**StrComp**](/tB/Modules/Strings/StrComp.md) compares two strings and returns -1, 0, or 1 to report which is greater (or equal). [**InStr**](/tB/Modules/Strings/InStr.md) and [**InStrRev**](/tB/Modules/Strings/InStrRev.md) return the position of one string inside another, scanning forward from a chosen start position or backward from one. All three accept an optional *compare* argument controlling whether the comparison is case-sensitive (**vbBinaryCompare**), or case-insensitive (**vbTextCompare**); when it is omitted, **StrComp** and **InStr** follow the surrounding [**Option Compare**](/tB/Core/Option.md) setting. Note that **InStrRev** swaps the order of the haystack and needle arguments relative to **InStr**.

```tb check_build
Debug.Print InStr("Hello, world", "o")           ' 5  (first match, forward)
Debug.Print InStrRev("Hello, world", "o")        ' 9  (first match, reverse)
Debug.Print StrComp("ABC", "abc", vbTextCompare) ' 0  (equal under text compare)
```

## Substrings, padding, and trimming

[**Left**](/tB/Modules/Strings/Left.md), [**Mid**](/tB/Modules/Strings/Mid.md), and [**Right**](/tB/Modules/Strings/Right.md) extract a substring from the start, middle, or end of a string. **Mid** doubles as an l-value via the [**Mid =**](/tB/Core/Mid-equals.md) statement, which writes characters back into a string in place. [**Space**](/tB/Modules/Strings/Space.md) returns a run of spaces and [**String**](/tB/Modules/Strings/String.md) returns a run of any chosen character --- both useful for padding fixed-width output. [**LTrim**](/tB/Modules/Strings/LTrim.md), [**RTrim**](/tB/Modules/Strings/RTrim.md), and [**Trim**](/tB/Modules/Strings/Trim.md) strip leading, trailing, or both kinds of whitespace from a string.

```tb check_build
Dim S As String
S = "  Hello, world  "
Debug.Print "[" & Trim(S) & "]"     ' "[Hello, world]"
Debug.Print Left(Trim(S), 5)        ' "Hello"
Debug.Print String(3, "*") & " " & Space(2) & "!"   ' "***   !"
```

## Case folding and other transformations

[**LCase**](/tB/Modules/Strings/LCase.md) and [**UCase**](/tB/Modules/Strings/UCase.md) fold a string to lowercase or uppercase. [**StrReverse**](/tB/Modules/Strings/StrReverse.md) reverses the character order. [**StrConv**](/tB/Modules/Strings/StrConv.md) bundles a wider set of conversions --- case folding, proper-casing, narrow/wide and Hiragana/Katakana mapping for DBCS locales, and Unicode-to-ANSI byte-array round-tripping --- selected by an additive flag argument.

```tb check_build
Debug.Print UCase("Hello")               ' "HELLO"
Debug.Print StrReverse("Hello")          ' "olleH"
Debug.Print StrConv("hello world", vbProperCase)   ' "Hello World"
```

## Splitting, joining, replacing, filtering

[**Split**](/tB/Modules/Strings/Split.md) breaks a string apart at a delimiter into a zero-based array of substrings; [**Join**](/tB/Modules/Strings/Join.md) reverses the operation, gluing an array back together with a chosen separator between elements. [**Replace**](/tB/Modules/Strings/Replace.md) substitutes one substring for another across a string, optionally limited to a fixed number of replacements or starting from a given offset. [**Filter**](/tB/Modules/Strings/Filter.md) reduces a string array to only those elements that contain --- or, with *include* set to **False**, do not contain --- a chosen substring.

```tb check_build
Dim Parts() As String
Parts = Split("red,green,blue", ",")
Debug.Print Join(Parts, " / ")              ' "red / green / blue"
Debug.Print Replace("red,green,blue", ",", "; ")  ' "red; green; blue"
```

## Formatting values as text

[**Format**](/tB/Modules/Strings/Format.md) is the general-purpose formatter: it takes any expression --- number, date, or string --- together with a named or user-defined format string, and returns the rendered text. The four named-formatter functions [**FormatCurrency**](/tB/Modules/Strings/FormatCurrency.md), [**FormatNumber**](/tB/Modules/Strings/FormatNumber.md), [**FormatPercent**](/tB/Modules/Strings/FormatPercent.md), and [**FormatDateTime**](/tB/Modules/Strings/FormatDateTime.md) wrap the most common cases with explicit parameters in place of a format string, so the call site reads as the intent rather than as a recipe. [**MonthName**](/tB/Modules/Strings/MonthName.md) and [**WeekdayName**](/tB/Modules/Strings/WeekdayName.md) return the localised name (or abbreviation) of a month or day of the week, given its numeric index.

```tb check_build
Debug.Print Format(1234.5, "#,##0.00")         ' "1,234.50"
Debug.Print FormatCurrency(1234.5)             ' "$1,234.50"   (US locale)
Debug.Print FormatDateTime(Now, vbLongDate)    ' "Saturday, May 9, 2026"
Debug.Print MonthName(1)                       ' "January"
```

## Members

- [Asc](/tB/Modules/Strings/Asc.md) -- returns the character code of the first character in a string
- [Chr](/tB/Modules/Strings/Chr.md) -- returns the character associated with a character code
- [Filter](/tB/Modules/Strings/Filter.md) -- returns a subset of a string array matching (or not matching) a substring
- [Format](/tB/Modules/Strings/Format.md) -- formats an expression according to a format expression
- [FormatCurrency](/tB/Modules/Strings/FormatCurrency.md) -- formats an expression as a currency string
- [FormatDateTime](/tB/Modules/Strings/FormatDateTime.md) -- formats an expression as a date/time string
- [FormatNumber](/tB/Modules/Strings/FormatNumber.md) -- formats an expression as a numeric string
- [FormatPercent](/tB/Modules/Strings/FormatPercent.md) -- formats an expression as a percent string
- [InStr](/tB/Modules/Strings/InStr.md) -- returns the position of one string within another
- [InStrRev](/tB/Modules/Strings/InStrRev.md) -- returns the position of one string within another, searching from the end
- [Join](/tB/Modules/Strings/Join.md) -- concatenates a string array using a given delimiter
- [LCase](/tB/Modules/Strings/LCase.md) -- returns a string converted to lowercase
- [Left](/tB/Modules/Strings/Left.md) -- returns a leftmost substring of a string
- [Len](/tB/Modules/Strings/Len.md) -- returns the length of a string, or the storage size of a variable
- [LTrim](/tB/Modules/Strings/LTrim.md) -- removes leading spaces from a string
- [Mid](/tB/Modules/Strings/Mid.md) -- returns a substring of a string
- [MonthName](/tB/Modules/Strings/MonthName.md) -- returns the name of the specified month
- [Replace](/tB/Modules/Strings/Replace.md) -- replaces substrings within a string
- [Right](/tB/Modules/Strings/Right.md) -- returns a rightmost substring of a string
- [RTrim](/tB/Modules/Strings/RTrim.md) -- removes trailing spaces from a string
- [Space](/tB/Modules/Strings/Space.md) -- returns a string of spaces
- [Split](/tB/Modules/Strings/Split.md) -- splits a string into a string array on a delimiter
- [StrComp](/tB/Modules/Strings/StrComp.md) -- compares two strings
- [StrConv](/tB/Modules/Strings/StrConv.md) -- converts a string to a specified format
- [String](/tB/Modules/Strings/String.md) -- returns a string of repeating characters
- [StrReverse](/tB/Modules/Strings/StrReverse.md) -- reverses the order of characters of a string
- [Trim](/tB/Modules/Strings/Trim.md) -- removes leading and trailing spaces from a string
- [UCase](/tB/Modules/Strings/UCase.md) -- returns a string converted to uppercase
- [WeekdayName](/tB/Modules/Strings/WeekdayName.md) -- returns the name of the specified day of the week
