C# Class Nvelope.StringExtensions

Afficher le fichier Open project: TrinityWestern/Nvelope

Méthodes publiques

Méthode Description
Camelize ( this input, bool capitalizeFirst = false ) : string

Converts the input to camelCase

ChopEnd ( this source ) : string

Remove whitespace from source, and trim off any stringsToRemove if source ends with it

ChopStart ( this source ) : string

Remove whitespace from source, and trim off stringToRemove if source starts with it

ContainsAll ( this source ) : bool
ContainsAll ( this source, IEnumerable strings ) : bool
ContainsAny ( this source ) : bool
ContainsAny ( this source, IEnumerable strings ) : bool
EscapePowerShell ( this sentence ) : string

Assuming that your string in PowerShell is wrapped in double quotes, this will escape all of the characters in your sentence so that you can have things like passwords with back-ticks, ampersands, single-quotes, etc.

Excerpt ( this original, int maxLength ) : string

Limit the length of a string while keeping words intact, and adding ... to the end

FormatFromDictionary ( this str, string>.IDictionary dict ) : string

Functions like string.Format, only with a dictionary of values From: http://stackoverflow.com/questions/1010123/named-string-format-is-it-possible-c

IsNullOrEmpty ( this source ) : bool

Just a wrapper around String.IsNullOrEmpty so you can call it inline

Join ( this source, string seperator ) : string

Joins a list of strings together into a single string

Print ( this s ) : string This exists so that the compiler doesn't get confused and call the IEnumerable[char] version of Print on a string. Then you would get "(a,b)" from "ab".Print(), which is silly
RemoveEnd ( this source, int count ) : string

Removes the last 'count' number of characters. If the ask to remove a greater number of characters than exist in source returns an empty string.

Repeat ( this source, int times ) : string

Repeat a string times times

RetrieveIntFromAString ( string input ) : string

This method retrieves digits from a string

SentenceCase ( this sentence ) : string
Split ( this source, string splitby ) : string[]

Returns a string array that contains the substrings in this string that are delimited by elements of a specified string array. A parameter specifies whether to return empty array elements.

SplitPair ( this source, string splitby ) : string[]

Returns an array of two strings that are separated by the specified string.

Strip ( this source ) : string

Removes all instances of the supplied victims string(s)

This is not the same as Trim

SubstringAfter ( this source, string splitter ) : string

Gets the part of the string that comes after the given token. If the given token is not in the string, this returns null.

SubstringBefore ( this source, string splitter ) : string

Gets the part of the string that comes before the given token. If the given token is not in the string, this returns null.

ToLength ( this source, int length ) : string

Make the string the specified length - truncating or appending spaces as necessary

ToStringN ( this source ) : string

Converts to string, but handles null gracefully (converts to "")

Tokenize ( this source ) : IEnumerable

Splits the string by spaces

Tokenize ( this source, string regexExpression ) : IEnumerable

TrimN ( this source ) : string

Trim(), but handle nulls, leaving them as nulls

Truncate ( this source, int maxLength ) : string

Truncates a string down to the specified maxLength

UnCamelize ( this input, bool unCapitalize = false ) : string

Converts the input from camelCase to space seperated

Private Methods

Méthode Description
FindIntInString ( string input ) : string
GetEmailInParenthesis ( this source ) : string
GetIntegerInParenthesis ( this source ) : int?
NumTimesCharacterRepeatsAtEnd ( this original, char charToCheck ) : int
RetrieveIntInString ( string input ) : int
SemiClean ( string input ) : string
ToDoubleAsStringOr0 ( this source ) : string
ToIntOr0 ( this source ) : int
Tokenize ( this source, Regex regex ) : IEnumerable

Method Details

Camelize() public static méthode

Converts the input to camelCase
public static Camelize ( this input, bool capitalizeFirst = false ) : string
input this
capitalizeFirst bool
Résultat string

ChopEnd() public static méthode

Remove whitespace from source, and trim off any stringsToRemove if source ends with it
public static ChopEnd ( this source ) : string
source this
Résultat string

ChopStart() public static méthode

Remove whitespace from source, and trim off stringToRemove if source starts with it
public static ChopStart ( this source ) : string
source this
Résultat string

ContainsAll() public static méthode

public static ContainsAll ( this source ) : bool
source this
Résultat bool

ContainsAll() public static méthode

public static ContainsAll ( this source, IEnumerable strings ) : bool
source this
strings IEnumerable
Résultat bool

ContainsAny() public static méthode

public static ContainsAny ( this source ) : bool
source this
Résultat bool

ContainsAny() public static méthode

public static ContainsAny ( this source, IEnumerable strings ) : bool
source this
strings IEnumerable
Résultat bool

EscapePowerShell() public static méthode

Assuming that your string in PowerShell is wrapped in double quotes, this will escape all of the characters in your sentence so that you can have things like passwords with back-ticks, ampersands, single-quotes, etc.
public static EscapePowerShell ( this sentence ) : string
sentence this
Résultat string

Excerpt() public static méthode

Limit the length of a string while keeping words intact, and adding ... to the end
public static Excerpt ( this original, int maxLength ) : string
original this String to make an excerpt of
maxLength int Maximum length of the string (including the ...)
Résultat string

FormatFromDictionary() public static méthode

Functions like string.Format, only with a dictionary of values From: http://stackoverflow.com/questions/1010123/named-string-format-is-it-possible-c
public static FormatFromDictionary ( this str, string>.IDictionary dict ) : string
str this String to form
dict string>.IDictionary Dictionary to retrieve values from
Résultat string

IsNullOrEmpty() public static méthode

Just a wrapper around String.IsNullOrEmpty so you can call it inline
public static IsNullOrEmpty ( this source ) : bool
source this
Résultat bool

Join() public static méthode

Joins a list of strings together into a single string
public static Join ( this source, string seperator ) : string
source this
seperator string
Résultat string

Print() public static méthode

This exists so that the compiler doesn't get confused and call the IEnumerable[char] version of Print on a string. Then you would get "(a,b)" from "ab".Print(), which is silly
public static Print ( this s ) : string
s this
Résultat string

RemoveEnd() public static méthode

Removes the last 'count' number of characters. If the ask to remove a greater number of characters than exist in source returns an empty string.
public static RemoveEnd ( this source, int count ) : string
source this
count int
Résultat string

Repeat() public static méthode

Repeat a string times times
public static Repeat ( this source, int times ) : string
source this
times int
Résultat string

RetrieveIntFromAString() public static méthode

This method retrieves digits from a string
public static RetrieveIntFromAString ( string input ) : string
input string anything in a string
Résultat string

SentenceCase() public static méthode

public static SentenceCase ( this sentence ) : string
sentence this
Résultat string

Split() public static méthode

Returns a string array that contains the substrings in this string that are delimited by elements of a specified string array. A parameter specifies whether to return empty array elements.
public static Split ( this source, string splitby ) : string[]
source this The source string, usually the object you're calling the Extension method on.
splitby string The token to split by.
Résultat string[]

SplitPair() public static méthode

Returns an array of two strings that are separated by the specified string.
public static SplitPair ( this source, string splitby ) : string[]
source this The source string to be split into two items.
splitby string The string that the source is to be split by.
Résultat string[]

Strip() public static méthode

Removes all instances of the supplied victims string(s)
This is not the same as Trim
public static Strip ( this source ) : string
source this
Résultat string

SubstringAfter() public static méthode

Gets the part of the string that comes after the given token. If the given token is not in the string, this returns null.
public static SubstringAfter ( this source, string splitter ) : string
source this The source string, usually the object you're calling the Extension method on.
splitter string The token to look for and use to split the string in two pieces
Résultat string

SubstringBefore() public static méthode

Gets the part of the string that comes before the given token. If the given token is not in the string, this returns null.
public static SubstringBefore ( this source, string splitter ) : string
source this The source string, usually the object you're calling the Extension method on.
splitter string The token to look for and use to split the string in two pieces
Résultat string

ToLength() public static méthode

Make the string the specified length - truncating or appending spaces as necessary
public static ToLength ( this source, int length ) : string
source this
length int
Résultat string

ToStringN() public static méthode

Converts to string, but handles null gracefully (converts to "")
public static ToStringN ( this source ) : string
source this
Résultat string

Tokenize() public static méthode

Splits the string by spaces
public static Tokenize ( this source ) : IEnumerable
source this
Résultat IEnumerable

Tokenize() public static méthode

public static Tokenize ( this source, string regexExpression ) : IEnumerable
source this
regexExpression string An regex used to tokenize the string - the entire contents of the expression will /// be removed with each iteration, and the value of group 1 will be returned as the token value
Résultat IEnumerable

TrimN() public static méthode

Trim(), but handle nulls, leaving them as nulls
public static TrimN ( this source ) : string
source this
Résultat string

Truncate() public static méthode

Truncates a string down to the specified maxLength
public static Truncate ( this source, int maxLength ) : string
source this
maxLength int
Résultat string

UnCamelize() public static méthode

Converts the input from camelCase to space seperated
public static UnCamelize ( this input, bool unCapitalize = false ) : string
input this
unCapitalize bool
Résultat string