C# Class Nvelope.StringExtensions

Show file Open project: TrinityWestern/Nvelope

Public Methods

Method 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

Method 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 method

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

ChopEnd() public static method

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

ChopStart() public static method

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

ContainsAll() public static method

public static ContainsAll ( this source ) : bool
source this
return bool

ContainsAll() public static method

public static ContainsAll ( this source, IEnumerable strings ) : bool
source this
strings IEnumerable
return bool

ContainsAny() public static method

public static ContainsAny ( this source ) : bool
source this
return bool

ContainsAny() public static method

public static ContainsAny ( this source, IEnumerable strings ) : bool
source this
strings IEnumerable
return bool

EscapePowerShell() public static method

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
return string

Excerpt() public static method

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 ...)
return string

FormatFromDictionary() public static method

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
return string

IsNullOrEmpty() public static method

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

Join() public static method

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

Print() public static method

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
return string

RemoveEnd() public static method

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
return string

Repeat() public static method

Repeat a string times times
public static Repeat ( this source, int times ) : string
source this
times int
return string

RetrieveIntFromAString() public static method

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

SentenceCase() public static method

public static SentenceCase ( this sentence ) : string
sentence this
return string

Split() public static method

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.
return string[]

SplitPair() public static method

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.
return string[]

Strip() public static method

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

SubstringAfter() public static method

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
return string

SubstringBefore() public static method

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
return string

ToLength() public static method

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

ToStringN() public static method

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

Tokenize() public static method

Splits the string by spaces
public static Tokenize ( this source ) : IEnumerable
source this
return IEnumerable

Tokenize() public static method

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
return IEnumerable

TrimN() public static method

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

Truncate() public static method

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

UnCamelize() public static method

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