String Module
String utility functions — functional wrappers over String methods.
Functions and values
| Function or value |
Description
|
Full Usage:
String.contains value str
Parameters:
string
-
The substring to search for.
str : string
-
The string to search in.
Returns: bool
Modifiers: inline |
Returns
|
Full Usage:
String.containsAny comparison values str
Parameters:
StringComparison
-
The string comparison mode to use.
values : string[]
-
The substrings to search for.
str : string
-
The string to search in.
Returns: bool
|
Returns
|
Full Usage:
String.containsAnyChar values str
Parameters:
char[]
-
The characters to search for.
str : string
-
The string to search in.
Returns: bool
|
Returns
|
Full Usage:
String.countOccurrences substr str
Parameters:
string
-
The substring to count.
str : string
-
The string to search in.
Returns: int
Number of occurrences; 0 for null/empty input or null/empty substr.
|
Counts the number of non-overlapping occurrences of substr in str.
Null-hardened: a
Example
module String
from Microsoft.FSharp.Core
|
Full Usage:
String.defaultIfEmpty defaultValue str
Parameters:
string
str : string
Returns: string
Modifiers: inline |
Returns the default value if the string is null or empty. The fallback value. The string to test.
|
Full Usage:
String.endsWith value str
Parameters:
string
-
The suffix to look for.
str : string
-
The string to check.
Returns: bool
Modifiers: inline |
Returns
|
Full Usage:
String.endsWithAny comparison values str
Parameters:
StringComparison
-
The string comparison mode to use.
values : string[]
-
The suffixes to test against.
str : string
-
The string to check.
Returns: bool
|
Returns
|
Full Usage:
String.endsWithAnyChar values str
Parameters:
char[]
-
The characters to test against.
str : string
-
The string to check.
Returns: bool
|
Returns
|
Full Usage:
String.equalsAny comparison values str
Parameters:
StringComparison
-
The string comparison mode to use.
values : string[]
-
The candidates to test against.
str : string
-
The string to check.
Returns: bool
|
Returns Null policy matches startsWithAny: null subject/collection never match; a null element of values can equal only a non-null str, so it never spuriously matches a null subject even though Equals(string,string,StringComparison) treats two nulls as equal. comparison is a normal required parameter rather than an overload pair, so the comparison mode is always explicit at the call site.
|
Full Usage:
String.equalsAnyChar values str
Parameters:
char[]
-
The characters to test against.
str : string
-
The string to check.
Returns: bool
|
Returns
Null policy: a
|
Full Usage:
String.isNotNullOrWhiteSpace
Returns: string -> bool
|
Returns true if string is not null/empty/whitespace.
|
Full Usage:
String.isNullOrEmpty value
Parameters:
string
Returns: bool
|
Returns true if the string is null or empty (no whitespace check).
|
Full Usage:
String.isNullOrWhiteSpace value
Parameters:
string
Returns: bool
|
Returns true if string is null, empty, or only whitespace.
|
Full Usage:
String.join separator values
Parameters:
string
-
The delimiter placed between elements.
values : string seq
-
The strings to join.
Returns: string
Modifiers: inline |
Joins a sequence of strings with the given separator.
Null-hardened: a
|
Full Usage:
String.padLeft totalWidth str
Parameters:
int
str : string
Returns: string
Modifiers: inline |
Pads the string on the left to the given total width. The desired total length after padding. The string to pad.
|
Full Usage:
String.padRight totalWidth str
Parameters:
int
str : string
Returns: string
Modifiers: inline |
Pads the string on the right to the given total width. The desired total length after padding. The string to pad.
|
Full Usage:
String.remove value str
Parameters:
string
str : string
Returns: string
Modifiers: inline |
Removes all occurrences of value from the string. The substring to remove. The input string.
|
Full Usage:
String.replace oldValue newValue str
Parameters:
string
newValue : string
str : string
Returns: string
Modifiers: inline |
Replaces all occurrences of oldValue with newValue. The substring to find. The replacement string. The input string.
|
Full Usage:
String.replaceEndLines replacementText str
Parameters:
string
-
The text to substitute for line endings.
str : string
-
The input string.
Returns: string
|
Replaces all line-ending sequences with the given replacement text.
Null-hardened: returns
|
Full Usage:
String.split separator str
Parameters:
string
str : string
Returns: string[]
Modifiers: inline |
Splits a string by the given separator. The delimiter string. The string to split.
|
Full Usage:
String.splitChar separator str
Parameters:
char
str : string
Returns: string[]
Modifiers: inline |
Splits a string by the given char separator. The delimiter character. The string to split.
|
Full Usage:
String.startsWith value str
Parameters:
string
-
The prefix to look for.
str : string
-
The string to check.
Returns: bool
Modifiers: inline |
Returns
|
Full Usage:
String.startsWithAny values str
Parameters:
string[]
-
The prefixes to test against.
str : string
-
The string to check.
Returns: bool
|
Returns
Null policy: a
Example
module String
from Microsoft.FSharp.Core
|
Full Usage:
String.substring idx str
Parameters:
int
str : string
Returns: string
Modifiers: inline |
Returns the substring starting at the given index. The zero-based start index. The input string.
|
Full Usage:
String.substringLen idx length str
Parameters:
int
length : int
str : string
Returns: string
Modifiers: inline |
Returns the substring starting at idx with the given length. The zero-based start index. The number of characters to extract. The input string.
|
Full Usage:
String.toLower str
Parameters:
string
Returns: string
|
Converts a string to lowercase using the current culture. The string to convert.
|
Full Usage:
String.toLowerInv str
Parameters:
string
Returns: string
|
Converts a string to lowercase using invariant culture. The string to convert.
|
Full Usage:
String.toOption s
Parameters:
string
-
The string to evaluate.
Returns: string option
Modifiers: inline |
Returns
|
Full Usage:
String.toUpper str
Parameters:
string
Returns: string
|
Converts a string to uppercase using the current culture. The string to convert.
|
Full Usage:
String.toUpperInv str
Parameters:
string
Returns: string
|
Converts a string to uppercase using invariant culture. The string to convert.
|
Full Usage:
String.trim str
Parameters:
string
Returns: string
Modifiers: inline |
Removes leading and trailing whitespace. The string to trim.
|
Full Usage:
String.trimEnd str
Parameters:
string
Returns: string
Modifiers: inline |
Removes trailing whitespace. The string to trim.
|
Full Usage:
String.trimStart str
Parameters:
string
Returns: string
Modifiers: inline |
Removes leading whitespace. The string to trim.
|
Full Usage:
String.truncate maxLen str
Parameters:
int
-
Maximum length of the returned string.
str : string
-
The string to truncate.
Returns: string
|
Returns at most maxLen characters from the start of the string. Null-safe: returns null if input is null.
Example
module String
from Microsoft.FSharp.Core
|
TDesu.FSharp