ExtensionsString Module
Extension methods for System.String. Adds extension members on System.String. E.G. .First, .Second, .Last and similar indices. Also adds functionality for negative indices, and s.SliceNeg, s.SliceIdx and s.SliceLooped with an inclusive end index. This module is NOT automatically opened when the namespace Str is opened.
Types
| Type | Description |
|
An Exception for the string functions defined in Str |
Functions and values
| Function or value |
Description
|
Full Usage:
exnf s
Parameters:
string
Returns: string
|
For string formatting in exceptions. Including surrounding quotes
|
Type extensions
| Type extension |
Description
|
||
Full Usage:
this.First
Parameters:
unit
Returns: char
Modifiers: inline |
Returns the first character of the string Fails if the string is empty.
Extended Type:
|
||
Full Usage:
this.Get
Parameters:
int
Returns: char
Modifiers: inline |
Gets a character at an index, the same as this.[index] or this.Idx(index). Throws a descriptive Exception if the index is out of range. (Use this.GetNeg(i) member if you want to use negative indices too)
Extended Type:
|
||
Full Usage:
this.GetLooped
Parameters:
int
Returns: char
|
Any index returns a value for a non-empty string. The string is treated as an endless loop in both positive and negative directions. Throws StrException if the string is empty.
Extended Type:
|
||
Full Usage:
this.GetNeg
Parameters:
int
Returns: char
|
Gets an item in the string by index. Allows negative indexes too (-1 is the last item, as in Python). (With LangVersion preview, F# also supports indexing from the end with the '^' prefix, e.g. str.[^0] for the last item.)
Extended Type:
|
||
Full Usage:
this.Idx
Parameters:
int
Returns: char
Modifiers: inline |
Gets a character at an index, the same as this.[index] or this.Get(index). Throws a descriptive Exception if the index is out of range. (Use this.GetNeg(i) member if you want to use negative indices too)
Extended Type:
|
||
Full Usage:
this.Last
Parameters:
unit
Returns: char
Modifiers: inline |
Returns the last character of the string Fails if the string is empty.
Extended Type:
|
||
Full Usage:
this.LastIndex
Parameters:
unit
Returns: int
Modifiers: inline |
Returns the last valid index in the string same as: s.Length - 1
Extended Type:
|
||
Full Usage:
this.LastX
Parameters:
int
Returns: string
Modifiers: inline |
Returns the last x characters of the string. x must be between zero and the string length.
Extended Type:
|
||
Full Usage:
this.ReplaceFirst
Parameters:
string
newValue : string
Returns: string
|
Returns a new string in which only the first occurrence of a specified string in the current instance is replaced with another specified string. (Will return the same instance if text to replace is not found) An empty oldValue is treated as a no-op and returns the input unchanged.
Extended Type:
|
||
Full Usage:
this.ReplaceLast
Parameters:
string
newValue : string
Returns: string
|
Returns a new string in which only the last occurrence of a specified string in the current instance is replaced with another specified string. (Will return the same instance if text to replace is not found) An empty oldValue is treated as a no-op and returns the input unchanged.
Extended Type:
|
||
Full Usage:
this.Second
Parameters:
unit
Returns: char
Modifiers: inline |
Returns the second character of the string Fails if the string has fewer than two characters.
Extended Type:
|
||
Full Usage:
this.SecondLast
Parameters:
unit
Returns: char
Modifiers: inline |
Returns the second last character of the string Fails if the string has fewer than two characters.
Extended Type:
|
||
Full Usage:
this.SliceIdx
Parameters:
int
-
The inclusive start index of the slice.
endIdx : int
-
The inclusive end index of the slice.
Returns: string
A new string containing the requested range.
|
Returns a new string containing the characters between the specified inclusive start and end indices. This member rejects negative and out-of-bounds indices, while the F# slicing notation str.[1..3] does not. To allow negative indices use SliceNeg, to normalize any index with modulo use SliceLooped.
Extended Type:
|
||
Full Usage:
this.SliceLooped
Parameters:
int
-
The inclusive start index to normalize.
endIdx : int
-
The inclusive end index to normalize.
Returns: string
A new string containing the requested range.
|
Returns a new string containing the characters between the specified start and end indices after normalizing both indices with modulo. Both indices are inclusive, and negative and out-of-range indices are allowed. If the normalized start index is greater than the normalized end index, an empty string is returned. For an empty input string, an empty string is returned.
Extended Type:
|
||
Full Usage:
this.SliceNeg
Parameters:
int
-
The start index (inclusive, can be negative).
endIdx : int
-
The end index (inclusive, can be negative).
Returns: string
A new string containing the sliced characters.
|
Allows for negative indices too. ( -1 is the last character, like Python) The resulting string includes the end index. If the end index is one less than the start index an empty string is returned. For example, str.SliceNeg(0,-3) trims the last two characters from the string. To reject negative indices use SliceIdx, to normalize any index with modulo use SliceLooped. (With LangVersion preview, F# also supports slicing from the end with the '^' prefix, e.g. str.[1..^1] skips the first and last character.)
Extended Type:
|
||
Full Usage:
this.Third
Parameters:
unit
Returns: char
Modifiers: inline |
Returns the third character of the string Fails if the string has fewer than three characters.
Extended Type:
|
||
Full Usage:
this.ThirdLast
Parameters:
unit
Returns: char
Modifiers: inline |
Returns the third last character of the string Fails if the string has fewer than three characters.
Extended Type:
|
Str