Header menu logo TDesu.FSharp

String Module

String utility functions — functional wrappers over String methods.

Functions and values

Function or value Description

String.contains value str

Full Usage: String.contains value str

Parameters:
    value : string
    str : string

Returns: bool
Modifiers: inline

Returns true if str contains value (ordinal). The substring to search for. The string to search in.

value : string
str : string
Returns: bool

String.countOccurrences substr str

Full Usage: String.countOccurrences substr str

Parameters:
    substr : string - The substring to count.
    str : string - The string to search in.

Returns: int Number of occurrences; 0 for empty input or empty substr.

Counts the number of non-overlapping occurrences of substr in str.

substr : string

The substring to count.

str : string

The string to search in.

Returns: int

Number of occurrences; 0 for empty input or empty substr.

Example

 "abcabc" |> String.countOccurrences "abc" // 2
module String from Microsoft.FSharp.Core

String.defaultIfEmpty defaultValue str

Full Usage: String.defaultIfEmpty defaultValue str

Parameters:
    defaultValue : 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.

defaultValue : string
str : string
Returns: string

String.endsWith value str

Full Usage: String.endsWith value str

Parameters:
    value : string
    str : string

Returns: bool
Modifiers: inline

Returns true if str ends with value. The suffix to look for. The string to check.

value : string
str : string
Returns: bool

String.isNotNullOrWhiteSpace

Full Usage: String.isNotNullOrWhiteSpace

Returns: string -> bool

Returns true if string is not null/empty/whitespace.

Returns: string -> bool

String.isNullOrEmpty value

Full Usage: String.isNullOrEmpty value

Parameters:
    value : string

Returns: bool

Returns true if the string is null or empty (no whitespace check).

value : string
Returns: bool

String.isNullOrWhiteSpace value

Full Usage: String.isNullOrWhiteSpace value

Parameters:
    value : string

Returns: bool

Returns true if string is null, empty, or only whitespace.

value : string
Returns: bool

String.join separator values

Full Usage: String.join separator values

Parameters:
    separator : string
    values : string seq

Returns: string
Modifiers: inline

Joins a sequence of strings with the given separator. The delimiter placed between elements. The strings to join.

separator : string
values : string seq
Returns: string

String.padLeft totalWidth str

Full Usage: String.padLeft totalWidth str

Parameters:
    totalWidth : 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.

totalWidth : int
str : string
Returns: string

String.padRight totalWidth str

Full Usage: String.padRight totalWidth str

Parameters:
    totalWidth : 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.

totalWidth : int
str : string
Returns: string

String.remove value str

Full Usage: String.remove value str

Parameters:
    value : string
    str : string

Returns: string
Modifiers: inline

Removes all occurrences of value from the string. The substring to remove. The input string.

value : string
str : string
Returns: string

String.replace oldValue newValue str

Full Usage: String.replace oldValue newValue str

Parameters:
    oldValue : 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.

oldValue : string
newValue : string
str : string
Returns: string

String.replaceEndLines replacementText str

Full Usage: String.replaceEndLines replacementText str

Parameters:
    replacementText : string
    str : string

Returns: string

Replaces all line-ending sequences with the given replacement text. The text to substitute for line endings. The input string.

replacementText : string
str : string
Returns: string

String.split separator str

Full Usage: String.split separator str

Parameters:
    separator : string
    str : string

Returns: string[]
Modifiers: inline

Splits a string by the given separator. The delimiter string. The string to split.

separator : string
str : string
Returns: string[]

String.splitChar separator str

Full Usage: String.splitChar separator str

Parameters:
    separator : char
    str : string

Returns: string[]
Modifiers: inline

Splits a string by the given char separator. The delimiter character. The string to split.

separator : char
str : string
Returns: string[]

String.startsWith value str

Full Usage: String.startsWith value str

Parameters:
    value : string
    str : string

Returns: bool
Modifiers: inline

Returns true if the string starts with the given prefix. The prefix to look for. The string to check.

value : string
str : string
Returns: bool

String.startsWithAny values str

Full Usage: String.startsWithAny values str

Parameters:
    values : string[] - The prefixes to test against.
    str : string - The string to check.

Returns: bool

Returns true if str starts with any of the values.

values : string[]

The prefixes to test against.

str : string

The string to check.

Returns: bool

String.substring idx str

Full Usage: String.substring idx str

Parameters:
    idx : int
    str : string

Returns: string
Modifiers: inline

Returns the substring starting at the given index. The zero-based start index. The input string.

idx : int
str : string
Returns: string

String.substringLen idx length str

Full Usage: String.substringLen idx length str

Parameters:
    idx : 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.

idx : int
length : int
str : string
Returns: string

String.toLower str

Full Usage: String.toLower str

Parameters:
    str : string

Returns: string

Converts a string to lowercase using the current culture. The string to convert.

str : string
Returns: string

String.toLowerInv str

Full Usage: String.toLowerInv str

Parameters:
    str : string

Returns: string

Converts a string to lowercase using invariant culture. The string to convert.

str : string
Returns: string

String.toOption s

Full Usage: String.toOption s

Parameters:
    s : string - The string to evaluate.

Returns: string option
Modifiers: inline

Returns None if the string is null/empty/whitespace, otherwise Some(s).

s : string

The string to evaluate.

Returns: string option

String.toUpper str

Full Usage: String.toUpper str

Parameters:
    str : string

Returns: string

Converts a string to uppercase using the current culture. The string to convert.

str : string
Returns: string

String.toUpperInv str

Full Usage: String.toUpperInv str

Parameters:
    str : string

Returns: string

Converts a string to uppercase using invariant culture. The string to convert.

str : string
Returns: string

String.trim str

Full Usage: String.trim str

Parameters:
    str : string

Returns: string
Modifiers: inline

Removes leading and trailing whitespace. The string to trim.

str : string
Returns: string

String.trimEnd str

Full Usage: String.trimEnd str

Parameters:
    str : string

Returns: string
Modifiers: inline

Removes trailing whitespace. The string to trim.

str : string
Returns: string

String.trimStart str

Full Usage: String.trimStart str

Parameters:
    str : string

Returns: string
Modifiers: inline

Removes leading whitespace. The string to trim.

str : string
Returns: string

String.truncate maxLen str

Full Usage: String.truncate maxLen str

Parameters:
    maxLen : 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.

maxLen : int

Maximum length of the returned string.

str : string

The string to truncate.

Returns: string
Example

 String.truncate 5 "hello world" // "hello"
module String from Microsoft.FSharp.Core

Type something to start searching.