C# Class Yea.DataTypes.ExtensionMethods.StringExtensions

String and StringBuilder extensions
Datei anzeigen Open project: OxPatient/Rule-Engine

Public Methods

Method Description
AlphaCharactersOnly ( this input ) : string

Keeps only alpha characters

AlphaNumericOnly ( this input ) : string

Keeps only alphanumeric characters

AppendLineFormat ( this builder, string format ) : StringBuilder

Does an AppendFormat and then an AppendLine on the StringBuilder

Center ( this input, int length, string padding = " " ) : string

Centers the input string (if it's longer than the length) and pads it using the padding string

Encode ( this input, Encoding originalEncodingUsing = null, Encoding encodingUsing = null ) : string

Converts a string to a string of another encoding

ExpandTabs ( this input, int tabSize = 4 ) : string

Expands tabs and replaces them with spaces

FilterOutText ( this input, string filter ) : string

Removes the filter text from the input.

FormatString ( this input ) : string

Formats a string based on the key/value pairs that are sent in

FormatString ( this input, object Object, string startSeperator = "{", string endSeperator = "}" ) : string

Formats a string based on the object's properties

FormatString ( this input, string format, IStringFormatter provider = null ) : string

Formats a string based on a format string passed in. The default formatter uses the following format: # = digits @ = alpha characters \ = escape char

FromBase64 ( this input ) : byte[]

Converts base 64 string to a byte array

FromBase64 ( this input, Encoding encodingUsing ) : string

Converts base 64 string based on the encoding passed in

IsAnagram ( this input1, string input2 ) : bool

Determines if the two strings are anagrams or not

IsCreditCard ( this creditCardNumber ) : bool

Checks if a credit card number is valid

IsUnicode ( this input ) : bool

Determines if a string is unicode

KeepFilterText ( this input, string filter ) : string

Removes everything that is not in the filter text from the input.

Left ( this input, int length ) : string

Gets the first x number of characters from the left hand side

MaskLeft ( this input, int endPosition = 4, char mask = '#' ) : string

Masks characters to the left ending at a specific character

MaskRight ( this input, int startPosition = 4, char mask = '#' ) : string

Masks characters to the right starting at a specific character

NextSequence ( this sequence, char min = ' ', char max = '~' ) : string

Function that is useful for generating a string in a series. so a becomes b, b becomes c, etc. and after hitting the max character, it goes to two characters (so ~ becomes aa, then ab, ac, etc).

NumberTimesOccurs ( this input, string match ) : int

returns the number of times a string occurs within the text

NumericOnly ( this input, bool keepNumericPunctuation = true ) : string

Keeps only numeric characters

Pluralize ( this word, CultureInfo culture = null ) : string

Pluralizes a word

RegexFormat ( this input, string format, string outputFormat, RegexOptions options = RegexOptions.None ) : string

Uses a regex to format the input string

RemoveExtraSpaces ( this input ) : string

Removes multiple spaces from a string and replaces it with a single space

Reverse ( this input ) : string

Reverses a string

Right ( this input, int length ) : string

Gets the last x number of characters from the right hand side

Singularize ( this word, CultureInfo culture = null ) : string

Singularizes a word

StripIllegalXml ( this content ) : string

Strips illegal characters for XML content

StripLeft ( this input, string characters = " " ) : string

Strips out any of the characters specified starting on the left side of the input string (stops when a character not in the list is found)

StripRight ( this input, string characters = " " ) : string

Strips out any of the characters specified starting on the right side of the input string (stops when a character not in the list is found)

ToBase64 ( this input, Encoding originalEncodingUsing = null ) : string

Converts from the specified encoding to a base 64 string

ToByteArray ( this input, Encoding encodingUsing = null ) : byte[]

Converts a string to a byte array

ToFirstCharacterUpperCase ( this input ) : string

Takes the first character of an input string and makes it uppercase

ToSentenceCapitalize ( this input ) : string

Capitalizes each sentence within the string

ToTitleCase ( this input ) : string

Capitalizes the first character of each word

Private Methods

Method Description
LevenshteinDistance ( this value1, string value2 ) : int

Method Details

AlphaCharactersOnly() public static method

Keeps only alpha characters
public static AlphaCharactersOnly ( this input ) : string
input this Input string
return string

AlphaNumericOnly() public static method

Keeps only alphanumeric characters
public static AlphaNumericOnly ( this input ) : string
input this Input string
return string

AppendLineFormat() public static method

Does an AppendFormat and then an AppendLine on the StringBuilder
public static AppendLineFormat ( this builder, string format ) : StringBuilder
builder this Builder object
format string Format string
return StringBuilder

Center() public static method

Centers the input string (if it's longer than the length) and pads it using the padding string
public static Center ( this input, int length, string padding = " " ) : string
input this
length int
padding string
return string

Encode() public static method

Converts a string to a string of another encoding
public static Encode ( this input, Encoding originalEncodingUsing = null, Encoding encodingUsing = null ) : string
input this input string
originalEncodingUsing System.Text.Encoding The type of encoding the string is currently using (defaults to ASCII)
encodingUsing System.Text.Encoding The type of encoding the string is converted into (defaults to UTF8)
return string

ExpandTabs() public static method

Expands tabs and replaces them with spaces
public static ExpandTabs ( this input, int tabSize = 4 ) : string
input this Input string
tabSize int Number of spaces
return string

FilterOutText() public static method

Removes the filter text from the input.
public static FilterOutText ( this input, string filter ) : string
input this Input text
filter string Regex expression of text to filter out
return string

FormatString() public static method

Formats a string based on the key/value pairs that are sent in
public static FormatString ( this input ) : string
input this Input string
return string

FormatString() public static method

Formats a string based on the object's properties
public static FormatString ( this input, object Object, string startSeperator = "{", string endSeperator = "}" ) : string
input this Input string
Object object Object to use to format the string
startSeperator string Seperator character/string to use to describe the start of the property name
endSeperator string Seperator character/string to use to describe the end of the property name
return string

FormatString() public static method

Formats a string based on a format string passed in. The default formatter uses the following format: # = digits @ = alpha characters \ = escape char
public static FormatString ( this input, string format, IStringFormatter provider = null ) : string
input this Input string
format string Format of the output string
provider IStringFormatter String formatter provider (defaults to GenericStringFormatter)
return string

FromBase64() public static method

Converts base 64 string to a byte array
public static FromBase64 ( this input ) : byte[]
input this Input string
return byte[]

FromBase64() public static method

Converts base 64 string based on the encoding passed in
public static FromBase64 ( this input, Encoding encodingUsing ) : string
input this Input string
encodingUsing System.Text.Encoding The type of encoding the string is using (defaults to UTF8)
return string

IsAnagram() public static method

Determines if the two strings are anagrams or not
public static IsAnagram ( this input1, string input2 ) : bool
input1 this Input 1
input2 string Input 2
return bool

IsCreditCard() public static method

Checks if a credit card number is valid
public static IsCreditCard ( this creditCardNumber ) : bool
creditCardNumber this Number to check
return bool

IsUnicode() public static method

Determines if a string is unicode
public static IsUnicode ( this input ) : bool
input this Input string
return bool

KeepFilterText() public static method

Removes everything that is not in the filter text from the input.
public static KeepFilterText ( this input, string filter ) : string
input this Input text
filter string Regex expression of text to keep
return string

Left() public static method

Gets the first x number of characters from the left hand side
public static Left ( this input, int length ) : string
input this Input string
length int x number of characters to return
return string

MaskLeft() public static method

Masks characters to the left ending at a specific character
public static MaskLeft ( this input, int endPosition = 4, char mask = '#' ) : string
input this Input string
endPosition int End position (counting from the left)
mask char Mask character to use
return string

MaskRight() public static method

Masks characters to the right starting at a specific character
public static MaskRight ( this input, int startPosition = 4, char mask = '#' ) : string
input this Input string
startPosition int Start position (counting from the left)
mask char Mask character to use
return string

NextSequence() public static method

Function that is useful for generating a string in a series. so a becomes b, b becomes c, etc. and after hitting the max character, it goes to two characters (so ~ becomes aa, then ab, ac, etc).
public static NextSequence ( this sequence, char min = ' ', char max = '~' ) : string
sequence this Current sequence
min char Min character
max char Max character
return string

NumberTimesOccurs() public static method

returns the number of times a string occurs within the text
public static NumberTimesOccurs ( this input, string match ) : int
input this input text
match string The string to match (can be regex)
return int

NumericOnly() public static method

Keeps only numeric characters
public static NumericOnly ( this input, bool keepNumericPunctuation = true ) : string
input this Input string
keepNumericPunctuation bool Determines if decimal places should be kept
return string

Pluralize() public static method

Pluralizes a word
public static Pluralize ( this word, CultureInfo culture = null ) : string
word this Word to pluralize
culture System.Globalization.CultureInfo Culture info used to pluralize the word (defaults to current culture)
return string

RegexFormat() public static method

Uses a regex to format the input string
public static RegexFormat ( this input, string format, string outputFormat, RegexOptions options = RegexOptions.None ) : string
input this Input string
format string Regex string used to
outputFormat string Output format
options RegexOptions Regex options
return string

RemoveExtraSpaces() public static method

Removes multiple spaces from a string and replaces it with a single space
public static RemoveExtraSpaces ( this input ) : string
input this Input string
return string

Reverse() public static method

Reverses a string
public static Reverse ( this input ) : string
input this Input string
return string

Right() public static method

Gets the last x number of characters from the right hand side
public static Right ( this input, int length ) : string
input this Input string
length int x number of characters to return
return string

Singularize() public static method

Singularizes a word
public static Singularize ( this word, CultureInfo culture = null ) : string
word this Word to singularize
culture System.Globalization.CultureInfo Culture info used to singularize the word (defaults to current culture)
return string

StripIllegalXml() public static method

Strips illegal characters for XML content
public static StripIllegalXml ( this content ) : string
content this Content
return string

StripLeft() public static method

Strips out any of the characters specified starting on the left side of the input string (stops when a character not in the list is found)
public static StripLeft ( this input, string characters = " " ) : string
input this Input string
characters string Characters to string (defaults to a space)
return string

StripRight() public static method

Strips out any of the characters specified starting on the right side of the input string (stops when a character not in the list is found)
public static StripRight ( this input, string characters = " " ) : string
input this Input string
characters string Characters to string (defaults to a space)
return string

ToBase64() public static method

Converts from the specified encoding to a base 64 string
public static ToBase64 ( this input, Encoding originalEncodingUsing = null ) : string
input this Input string
originalEncodingUsing System.Text.Encoding The type of encoding the string is using (defaults to UTF8)
return string

ToByteArray() public static method

Converts a string to a byte array
public static ToByteArray ( this input, Encoding encodingUsing = null ) : byte[]
input this input string
encodingUsing System.Text.Encoding The type of encoding the string is using (defaults to UTF8)
return byte[]

ToFirstCharacterUpperCase() public static method

Takes the first character of an input string and makes it uppercase
public static ToFirstCharacterUpperCase ( this input ) : string
input this Input string
return string

ToSentenceCapitalize() public static method

Capitalizes each sentence within the string
public static ToSentenceCapitalize ( this input ) : string
input this Input string
return string

ToTitleCase() public static method

Capitalizes the first character of each word
public static ToTitleCase ( this input ) : string
input this Input string
return string