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.Slice(startIdx:int , endIdx: int) that works with negative numbers. 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). (Since F# 5, from-end indexes can also use the '^' prefix in index expressions, 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)
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)
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.Slice
Parameters:
int
endIdx : int
Returns: string
|
Allows for negative indices too. -1 is last character Includes end index in string For example, str.Slice(0,-3) trims the last two characters from the string.
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