# String functions

This topic is part of the manual Field Codes Reference Guide for version Current of Routing.

## Contents

Learn about the string functions you can use in field codes.

Related documentation:

## Find

Find(SearchIn, SearchFor)

Finds a substring within a string. Returns the 0-based character position of the found substring. Returns –1 if the substring is not found.

Argument Description
SearchIn The string to search in.
SearchFor The string to search for.
Examples of Find String
Example Result
<\$Find("Hello, World!", "H")\$> 0
<\$Find("Hello, World!", "lo")\$> 3
<\$Find("Hello, World!", "Qbert")\$> -1

## Left

Left(String, Number)

Returns a string containing a specified number of characters from the left side of a specified string.

Argument Description
String The string from which the leftmost characters are returned.
Number The number of characters to return. If 0, an empty string ("") is returned. If greater than the length of String, then the entire string is returned.

Examples of Left String
Example Result
<\$Left("Hello, World!", 5)\$> "Hello"
<\$Left("Hello, World!", 0)\$> ""
<\$Left("Hello, World!", 25)\$> "Hello, World!"

## Length

Length(String)

Returns the length of a string.

Example of Length String
Example Result
<\$Length("Hello")\$> 5

## Mid

Mid(String, Start, Length)

Returns a specified substring of a string.

Argument Description
String The string from which the substring is returned.
Start The 0-based character position at which the substring begins. If Start is greater than the length of String, then an empty string ("") is returned.
Length The number of characters to return. If Length is 0, then an empty string ("") is returned. If Length is greater than the portion of String after Start, then all the characters after Start are returned.
Examples of Mid String
Example Result
<\$Mid("Hello, World!", 2, 3)\$> "llo"
<\$Mid("Hello, World!", 25, 5)\$> ""
<\$Mid("Hello, World!", 7, 25)\$> "World!"

## Replace

Replace(String, Find, ReplaceWith)

Returns a string in which all instances of a specified substring have been replaced with another string.

Argument Description
String The string containing the substring to replace
Find The substring to search for
ReplaceWith The replacement string
Examples of Replace String
Example Result
<\$Replace("Hello", "l", "*")\$> "He**o"
<\$Mid("Hello", "j", "*")\$> "Hello"
<\$Mid("Hello", "Hello", "")\$> ""

## Right

Right(String, Number)

Returns a string containing a specified number of characters from the right side of a specified string.

Argument Description
String The string from which the rightmost characters are returned.
Number The number of characters to return. If 0, an empty string ("") is returned. If greater than the length of String, then the entire string is returned.
Examples of Right String
Example Result
<\$Right("Hello, World!", 5)\$> "orld!"
<\$Right("Hello, World!", 0)\$> ""
<\$Right("Hello, World!", 25)\$> "Hello, World!"

## ToLower

ToLower(String)

Returns a string that has been converted to lowercase.

Example of ToLower String
Example Result
<\$ToLower("Hello, World!")\$> "hello, world!"

## ToUpper

ToUpper(String)

Returns a string that has been converted to uppercase.

Example of ToUpper String
Example Result
<\$ToUpper("Hello, World!")\$> "HELLO, WORLD!"

## Trim

Trim(String, [CharSet])

Returns a copy of a specified string without specified leading or trailing characters.

Argument Description
String The string from which to trim
CharSet Optional. The characters to trim. If omitted, then white space (" \t\r\n") is trimmed.
Examples of Trim String
Example Result
<\$Trim(" Howdie ")\$> "Howdie"
<\$Trim("Howdie", "Howd")\$> "ie"
<\$Trim("Howdy", "y")\$> "Howd"

## TrimLeft

TrimLeft(String, [CharSet])

The same as Trim, except it trims only leading characters.

## TrimRight

TrimRight(String, [CharSet])

The same as Trim, except it trims only trailing characters.

## Wrap

Trim(String, LineLength, [LinePrefix, [Eol]])

Returns a string that has been word-wrapped to a specified line length.

Argument Description
String The string to wrap.
LineLength The maximum length, in characters, of any line, including LinePrefix (if specified), but not Eol.
LinePrefix Optional. A string to prefix to each line. Often used to “quote” e-mails being replied to. If omitted, lines are not prefixed.
Eol Optional. A string to use as a line terminator. If omitted, lines are terminated with "\r\n" as usual.
Example: <\$Wrap(> "Once upon a midnight dreary",< 11,< ">",< "*\r\n")\$>

Result: >Once upon*< >a midnight*< >dreary*