String Module
Functional programming operators for string processing. Further string operations are available via the member functions on strings and other functionality in System.String and System.Text.RegularExpressions types.
Functions and values
Function or value | Description | ||
|
ExampleThe following samples shows how to interspace spaces in a text
val input: string
module String
from Microsoft.FSharp.Core
val collect: mapping: (char -> string) -> str: string -> string
val sprintf: format: Printf.StringFormat<'T> -> 'T
The sample evaluates to "S t e f a n s a y s : H i ! "
ExampleHow to show the ASCII representation of a very secret text
module String
from Microsoft.FSharp.Core
val collect: mapping: (char -> string) -> str: string -> string
val chr: char
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val sprintf: format: Printf.StringFormat<'T> -> 'T
The sample evaluates to "83 101 99 114 101 116 "
|
||
Full Usage:
String.concat sep strings
Parameters:
string
-
The separator string to be inserted between the strings
of the input sequence.
strings : string seq
-
The sequence of strings to be concatenated.
Returns: string
A new string consisting of the concatenated strings separated by
the separation string.
|
Example
val input1: string list
module String
from Microsoft.FSharp.Core
val concat: sep: string -> strings: string seq -> string
val input2: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val map: mapping: ('T -> 'U) -> list: 'T list -> 'U list
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val input3: string list
|
||
|
ExampleLooking for uppercase characters
namespace System
Multiple items
type String = interface IEnumerable<char> interface IEnumerable interface ICloneable interface IComparable interface IComparable<string> interface IConvertible interface IEquatable<string> interface IParsable<string> interface ISpanParsable<string> new: value: nativeptr<char> -> unit + 8 overloads ... <summary>Represents text as a sequence of UTF-16 code units.</summary> -------------------- String(value: nativeptr<char>) : String String(value: char array) : String String(value: ReadOnlySpan<char>) : String String(value: nativeptr<sbyte>) : String String(c: char, count: int) : String String(value: nativeptr<char>, startIndex: int, length: int) : String String(value: char array, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : String val exists: predicate: (char -> bool) -> str: string -> bool
[<Struct>]
type Char =
member CompareTo: value: char -> int + 1 overload
member Equals: obj: char -> bool + 1 overload
member GetHashCode: unit -> int
member GetTypeCode: unit -> TypeCode
member ToString: unit -> string + 2 overloads
static member ConvertFromUtf32: utf32: int -> string
static member ConvertToUtf32: highSurrogate: char * lowSurrogate: char -> int + 1 overload
static member GetNumericValue: c: char -> float + 1 overload
static member GetUnicodeCategory: c: char -> UnicodeCategory + 1 overload
static member IsAscii: c: char -> bool
...
<summary>Represents a character as a UTF-16 code unit.</summary> Char.IsUpper(c: char) : bool
Char.IsUpper(s: string, index: int) : bool |
||
|
Returns an empty string if the input string is null
ExampleFiltering out just alphanumeric characters
namespace System
val input: string
Multiple items
type String = interface IEnumerable<char> interface IEnumerable interface ICloneable interface IComparable interface IComparable<string> interface IConvertible interface IEquatable<string> interface IParsable<string> interface ISpanParsable<string> new: value: nativeptr<char> -> unit + 8 overloads ... <summary>Represents text as a sequence of UTF-16 code units.</summary> -------------------- String(value: nativeptr<char>) : String String(value: char array) : String String(value: ReadOnlySpan<char>) : String String(value: nativeptr<sbyte>) : String String(c: char, count: int) : String String(value: nativeptr<char>, startIndex: int, length: int) : String String(value: char array, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : String val filter: predicate: (char -> bool) -> str: string -> string
Multiple items
type Uri = interface ISpanFormattable interface IFormattable interface ISerializable new: uriString: string -> unit + 6 overloads member Equals: comparand: obj -> bool member GetComponents: components: UriComponents * format: UriFormat -> string member GetHashCode: unit -> int member GetLeftPart: part: UriPartial -> string member IsBaseOf: uri: Uri -> bool member IsWellFormedOriginalString: unit -> bool ... <summary>Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.</summary> -------------------- Uri(uriString: string) : Uri Uri(uriString: string, creationOptions: inref<UriCreationOptions>) : Uri Uri(uriString: string, uriKind: UriKind) : Uri Uri(baseUri: Uri, relativeUri: string) : Uri Uri(baseUri: Uri, relativeUri: Uri) : Uri Uri.IsHexDigit(character: char) : bool
ExampleFiltering out just digits
namespace System
Multiple items
type String = interface IEnumerable<char> interface IEnumerable interface ICloneable interface IComparable interface IComparable<string> interface IConvertible interface IEquatable<string> interface IParsable<string> interface ISpanParsable<string> new: value: nativeptr<char> -> unit + 8 overloads ... <summary>Represents text as a sequence of UTF-16 code units.</summary> -------------------- String(value: nativeptr<char>) : String String(value: char array) : String String(value: ReadOnlySpan<char>) : String String(value: nativeptr<sbyte>) : String String(c: char, count: int) : String String(value: nativeptr<char>, startIndex: int, length: int) : String String(value: char array, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : String val filter: predicate: (char -> bool) -> str: string -> string
[<Struct>]
type Char =
member CompareTo: value: char -> int + 1 overload
member Equals: obj: char -> bool + 1 overload
member GetHashCode: unit -> int
member GetTypeCode: unit -> TypeCode
member ToString: unit -> string + 2 overloads
static member ConvertFromUtf32: utf32: int -> string
static member ConvertToUtf32: highSurrogate: char * lowSurrogate: char -> int + 1 overload
static member GetNumericValue: c: char -> float + 1 overload
static member GetUnicodeCategory: c: char -> UnicodeCategory + 1 overload
static member IsAscii: c: char -> bool
...
<summary>Represents a character as a UTF-16 code unit.</summary> Char.IsDigit(c: char) : bool
Char.IsDigit(s: string, index: int) : bool |
||
|
ExampleLooking for lowercase characters
namespace System
Multiple items
type String = interface IEnumerable<char> interface IEnumerable interface ICloneable interface IComparable interface IComparable<string> interface IConvertible interface IEquatable<string> interface IParsable<string> interface ISpanParsable<string> new: value: nativeptr<char> -> unit + 8 overloads ... <summary>Represents text as a sequence of UTF-16 code units.</summary> -------------------- String(value: nativeptr<char>) : String String(value: char array) : String String(value: ReadOnlySpan<char>) : String String(value: nativeptr<sbyte>) : String String(c: char, count: int) : String String(value: nativeptr<char>, startIndex: int, length: int) : String String(value: char array, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : String val forall: predicate: (char -> bool) -> str: string -> bool
[<Struct>]
type Char =
member CompareTo: value: char -> int + 1 overload
member Equals: obj: char -> bool + 1 overload
member GetHashCode: unit -> int
member GetTypeCode: unit -> TypeCode
member ToString: unit -> string + 2 overloads
static member ConvertFromUtf32: utf32: int -> string
static member ConvertToUtf32: highSurrogate: char * lowSurrogate: char -> int + 1 overload
static member GetNumericValue: c: char -> float + 1 overload
static member GetUnicodeCategory: c: char -> UnicodeCategory + 1 overload
static member IsAscii: c: char -> bool
...
<summary>Represents a character as a UTF-16 code unit.</summary> Char.IsLower(c: char) : bool
Char.IsLower(s: string, index: int) : bool |
||
|
ExampleEnumerate digits ASCII codes
module String
from Microsoft.FSharp.Core
val init: count: int -> initializer: (int -> string) -> string
val i: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val sprintf: format: Printf.StringFormat<'T> -> 'T
The sample evaluates to: "48 49 50 51 52 53 54 55 56 57 "
|
||
|
ExamplePrinting the ASCII code for each characater in the string
val input: string
module String
from Microsoft.FSharp.Core
val iter: action: (char -> unit) -> str: string -> unit
val c: char
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Multiple items
The sample evaluates as val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int unit , but prints:
|
||
|
ExampleNumbering the characters and printing the associated ASCII code for each characater in the input string
val input: string
module String
from Microsoft.FSharp.Core
val iteri: action: (int -> char -> unit) -> str: string -> unit
val i: int
val c: char
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Multiple items
The sample evaluates as val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int unit , but prints:
|
||
|
ExampleGetting the length of different strings
module String
from Microsoft.FSharp.Core
val length: str: string -> int
|
||
|
ExampleChanging case to upper for all characters in the input string
namespace System
val input: string
Multiple items
type String = interface IEnumerable<char> interface IEnumerable interface ICloneable interface IComparable interface IComparable<string> interface IConvertible interface IEquatable<string> interface IParsable<string> interface ISpanParsable<string> new: value: nativeptr<char> -> unit + 8 overloads ... <summary>Represents text as a sequence of UTF-16 code units.</summary> -------------------- String(value: nativeptr<char>) : String String(value: char array) : String String(value: ReadOnlySpan<char>) : String String(value: nativeptr<sbyte>) : String String(c: char, count: int) : String String(value: nativeptr<char>, startIndex: int, length: int) : String String(value: char array, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int) : String String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : String val map: mapping: (char -> char) -> str: string -> string
[<Struct>]
type Char =
member CompareTo: value: char -> int + 1 overload
member Equals: obj: char -> bool + 1 overload
member GetHashCode: unit -> int
member GetTypeCode: unit -> TypeCode
member ToString: unit -> string + 2 overloads
static member ConvertFromUtf32: utf32: int -> string
static member ConvertToUtf32: highSurrogate: char * lowSurrogate: char -> int + 1 overload
static member GetNumericValue: c: char -> float + 1 overload
static member GetUnicodeCategory: c: char -> UnicodeCategory + 1 overload
static member IsAscii: c: char -> bool
...
<summary>Represents a character as a UTF-16 code unit.</summary> Char.ToUpper(c: char) : char
Char.ToUpper(c: char, culture: Globalization.CultureInfo) : char |
||
Example
module String
from Microsoft.FSharp.Core
val mapi: mapping: (int -> char -> char) -> str: string -> string
val i: int
val c: char
Evaluates to [ (0, 'O'); (1, 'K'); (2, '!') ] .
|
|||
|
Example
module String
from Microsoft.FSharp.Core
val replicate: count: int -> str: string -> string
Evaluates to "Do it!Do it!Do it!" .
|