C# Class Candor.StringExtensions

Various common use case extensions to System.String.
Show file Open project: michael-lang/candor-common

Public Methods

Method Description
CamelCaseToPhrase ( this text ) : string

Puts spaces in a camel cased string before each capital letter and makes the capital letters lower case.

GenerateTeaser ( this text, Int32 maxSentences, Int32 maxCharacters ) : string

Generates a teaser phrase from any body of text. If the text is shortened from the specified max length, an ellipsis ("...") is added.

LexicalAdd ( this source, LexicalCharacterSet charSet, System.Boolean ignoreCase, System.Boolean treatNonCharsAsSpace, Int32 count ) : String

Performs a lexicographical addition to a string by any amount. See http://wikipedia.org/wiki/Lexicographical_order, and further remarks for this member.

This may or may not result in a value that sorts in the correct order as if it were a file name in a file explorer.

If the string is at the highest character for each position or the number added moves past that position, then a new character position is incremented to the left (by adding a character position). This then behaves the same as if the source was left whitespace padded. Performance scales based on the number of characters incremented in the string.

Incrementing the value always starts on the right and moves left as with numeric additions. Right whitespace padded strings will increment values in the whitespace before advancing to the characters on the left. If this is not desired behavior then Trim the source when passed into this method.

LexicalAdd ( this source, LexicalCharacterSet charSet, System.Boolean ignoreCase, Int32 count ) : String

Performs a lexicographical addition to a string by any amount. See http://wikipedia.org/wiki/Lexicographical_order, and further remarks for this member.

This may or may not result in a value that sorts in the correct order as if it were a file name in a file explorer.

If the string is at the highest character for each position or the number added moves past that position, then a new character position is incremented to the left (by adding a character position). This then behaves the same as if the source was left whitespace padded. Performance scales based on the number of characters incremented in the string.

Incrementing the value always starts on the right and moves left as with numeric additions. Right whitespace padded strings will increment values in the whitespace before advancing to the characters on the left. If this is not desired behavior then Trim the source when passed into this method.

LexicalIncrement ( this source, LexicalCharacterSet charSet, System.Boolean ignoreCase ) : String

Increments a source string to the next logical higher value. Characters are incremented without altering length first. If all character positions are at the highest character, then a new lowest value character is added to the end.

RemoveDiacritics ( this text ) : string

Removes diacritics from a text body.

a sign, such as an accent or cedilla, which when written above or below a letter indicates a difference in pronunciation from the same letter when unmarked or differently marked.

ReplaceNotIn ( this text, IList chars, String replacement ) : string

Replaces all characters in a text string that are not in a given list.

ToDigitsOnly ( this input ) : string

Gets only the digits portion of a string.

ToPascalCase ( this text ) : string

Converts a sentence or _ separated word string into a no whitespace/underscore pascal case name.

ToProperNameCase ( this text ) : string

Converts a string to a format of a proper name. Each word is capitalized. underscores become spaces (word boundaries). Acronyms are assumed when the text is all letters in all caps, and then no change is made.

ToSentence ( this text ) : string

Converts a string to a sentence, making word boundaries at capital letters following a lower case letter and replacing underscores with a space.

TrimEndNotIn ( this text, IList chars ) : string

Trims any characters from the end of a string that is not in the supplied list.

TrimNotIn ( this text, IList chars ) : string

Trims any characters from the start and end of a string that is not in the supplied list.

TrimStartNotIn ( this text, IList chars ) : string

Trims any characters from the start of a string that is not in the supplied list.

Method Details

CamelCaseToPhrase() public static method

Puts spaces in a camel cased string before each capital letter and makes the capital letters lower case.
public static CamelCaseToPhrase ( this text ) : string
text this
return string

GenerateTeaser() public static method

Generates a teaser phrase from any body of text. If the text is shortened from the specified max length, an ellipsis ("...") is added.
public static GenerateTeaser ( this text, Int32 maxSentences, Int32 maxCharacters ) : string
text this The original body text.
maxSentences System.Int32 The max number of sentences from the original text.
maxCharacters System.Int32 The maximum total characters to return.
return string

LexicalAdd() public static method

Performs a lexicographical addition to a string by any amount. See http://wikipedia.org/wiki/Lexicographical_order, and further remarks for this member.

This may or may not result in a value that sorts in the correct order as if it were a file name in a file explorer.

If the string is at the highest character for each position or the number added moves past that position, then a new character position is incremented to the left (by adding a character position). This then behaves the same as if the source was left whitespace padded. Performance scales based on the number of characters incremented in the string.

Incrementing the value always starts on the right and moves left as with numeric additions. Right whitespace padded strings will increment values in the whitespace before advancing to the characters on the left. If this is not desired behavior then Trim the source when passed into this method.

public static LexicalAdd ( this source, LexicalCharacterSet charSet, System.Boolean ignoreCase, System.Boolean treatNonCharsAsSpace, Int32 count ) : String
source this The string to increment from.
charSet LexicalCharacterSet The character set defining the characters and their order.
ignoreCase System.Boolean Specifies if case should be ignored as an incremented value. /// If true, incremented character positions will be the case of the majority of other /// values; which may or may not be the same as the character being replaced.
treatNonCharsAsSpace System.Boolean /// Indicates if non character set characters should be treated as /// a space and be eligible for incrementing. ///
count System.Int32
return String

LexicalAdd() public static method

Performs a lexicographical addition to a string by any amount. See http://wikipedia.org/wiki/Lexicographical_order, and further remarks for this member.

This may or may not result in a value that sorts in the correct order as if it were a file name in a file explorer.

If the string is at the highest character for each position or the number added moves past that position, then a new character position is incremented to the left (by adding a character position). This then behaves the same as if the source was left whitespace padded. Performance scales based on the number of characters incremented in the string.

Incrementing the value always starts on the right and moves left as with numeric additions. Right whitespace padded strings will increment values in the whitespace before advancing to the characters on the left. If this is not desired behavior then Trim the source when passed into this method.

public static LexicalAdd ( this source, LexicalCharacterSet charSet, System.Boolean ignoreCase, Int32 count ) : String
source this The string to increment from.
charSet LexicalCharacterSet The character set defining the characters and their order.
ignoreCase System.Boolean Specifies if case should be ignored as an incremented value. /// If true, incremented character positions will be the case of the majority of other /// values; which may or may not be the same as the character being replaced.
count System.Int32
return String

LexicalIncrement() public static method

Increments a source string to the next logical higher value. Characters are incremented without altering length first. If all character positions are at the highest character, then a new lowest value character is added to the end.
public static LexicalIncrement ( this source, LexicalCharacterSet charSet, System.Boolean ignoreCase ) : String
source this The source string.
charSet LexicalCharacterSet The character set to use. If the source string characters do not all fit in this set, an exception is thrown.
ignoreCase System.Boolean Specified if case is to be ignored for alpha characters.
return String

RemoveDiacritics() public static method

Removes diacritics from a text body.
a sign, such as an accent or cedilla, which when written above or below a letter indicates a difference in pronunciation from the same letter when unmarked or differently marked.
public static RemoveDiacritics ( this text ) : string
text this
return string

ReplaceNotIn() public static method

Replaces all characters in a text string that are not in a given list.
public static ReplaceNotIn ( this text, IList chars, String replacement ) : string
text this The text to be scanned.
chars IList The characters to be kept, such as a LexicalCharacterSet characters list.
replacement String The string to put in place of each character not in 'chars'.
return string

ToDigitsOnly() public static method

Gets only the digits portion of a string.
public static ToDigitsOnly ( this input ) : string
input this
return string

ToPascalCase() public static method

Converts a sentence or _ separated word string into a no whitespace/underscore pascal case name.
public static ToPascalCase ( this text ) : string
text this
return string

ToProperNameCase() public static method

Converts a string to a format of a proper name. Each word is capitalized. underscores become spaces (word boundaries). Acronyms are assumed when the text is all letters in all caps, and then no change is made.
public static ToProperNameCase ( this text ) : string
text this
return string

ToSentence() public static method

Converts a string to a sentence, making word boundaries at capital letters following a lower case letter and replacing underscores with a space.
public static ToSentence ( this text ) : string
text this
return string

TrimEndNotIn() public static method

Trims any characters from the end of a string that is not in the supplied list.
public static TrimEndNotIn ( this text, IList chars ) : string
text this The text to be scanned.
chars IList The characters to be kept, such as a LexicalCharacterSet characters list.
return string

TrimNotIn() public static method

Trims any characters from the start and end of a string that is not in the supplied list.
public static TrimNotIn ( this text, IList chars ) : string
text this The text to be scanned.
chars IList The characters to be kept, such as a LexicalCharacterSet characters list.
return string

TrimStartNotIn() public static method

Trims any characters from the start of a string that is not in the supplied list.
public static TrimStartNotIn ( this text, IList chars ) : string
text this The text to be scanned.
chars IList The characters to be kept, such as a LexicalCharacterSet characters list.
return string