C# Class Habanero.Util.StringUtilities

Provides a collection of utilities for strings
ファイルを表示 Open project: Chillisoft/habanero

Public Methods

Method Description
AppendMessage ( StringBuilder origStringBuilder, string appendedString, string separator ) : StringBuilder

Appends a given message to an existing message contained in a string builder

AppendMessage ( string origMessage, string messageToAppend ) : string

Appends a given message to an existing message, inserting a new line (carriage return) between the messages

AppendMessage ( string origMessage, string messageToAppend, string separator ) : string

Appends a given message to an existing message, using the given separator betweeen the two parts. Ensures that the seperator is only inserted between two appended messages. I.e. there will never be a trailing seperator.

BoolTryParse ( object valueToParse, bool &result ) : bool

Converts a string representing a boolean in one of many formats.

Camelize ( string input ) : string

Camel cases the input, removing spaces.

Classify ( string input ) : string

Create a classification of the input this is a Singular of the input Camel cased.

CountOccurrences ( string fullText, char token ) : int

Indicates the number of times a given token appears in a string

CountOccurrences ( string fullText, char token, int startIndex, int length ) : int

Indicates the number of times a given token appears in a string

CountOccurrences ( string fullText, string searchText ) : int

Indicates the number of times a given string appears in a larger string

CountOccurrences ( string fullText, string searchText, int startIndex, int length ) : int

Indicates the number of times a given string appears in a larger string

DelimitPascalCase ( string inputString, string delimiter ) : string

Breaks up a Pascal-cased string into sections that are divided by the given delimiter. For instance, an input string of "PascalCase" and a delimiter of " " will give "Pascal Case"

GetLeftSection ( string fullText, string searchText ) : string

Returns the portion of the string that is left of the given search text

GetNameValueCollection ( string nameValuePairString ) : NameValueCollection

returns a NameValueCollection of nameValue Pairs for the nameValuePairString. e.g. nameValuePairString = "name=value&name2=value2&name3=value3" will return a NameValueCollection with 3 items for name, name2 and name3.

GetRightSection ( string fullText, string searchText ) : string

Returns the portion of the string that is right of the given search text

GetValueString ( string nameValuePairString, string name ) : string

For a given name value pair e.g. a query string or cookie string that is formatted as name=value&name2=value2&name3=value3 etc this will return the value for a specified name e.g. for nameValuePairString = "name=value&name2=value2&name3=value3" and name = "name2" GetValueString will return value2.

GuidToUpper ( System.Guid guid ) : string

Returns the guid as a string with a standard format of "B" and with all the characters changed to upper.

GuidTryParse ( string s, System.Guid &result ) : bool

Converts the string representation of a Guid to its Guid equivalent. A return value indicates whether the operation succeeded.

Humanize ( string input ) : string

Replaces all _ with whites space

IsManyPascalWords ( string text ) : bool

Determines whether the word is already pascal cased. This will return true when.

PascalCaseTableName ( string text ) : string

Pascal Cases a table name that has as seperator '_', '-' or ' ' in it so that the the pascal casing will be done as follows first letter is capitalised the first letter that follows a seperator is capitalised. All other letters are left unchanged.

Pluralize ( string input ) : string

Pluralises a noun using standard rule e.g. Name => Names Pantry => Pantries.

RemovePrefix ( string prefix, string text ) : string

Removes a prefix defined by prefix from the text if it is found to be the leading characters of text.

ReplaceDoubleQuotesWithTwo ( string value ) : string

Replaces double quotes with two double quotes in the given string

ReplaceSingleQuotesWithTwo ( string value ) : string

Replaces single quotes with two single quotes in the given string

Singularize ( string input ) : string

Singularises the input string using heuristics and rule.

ToLowerFirstLetter ( string input ) : string

Changes the first character to a lowercase.

Private Methods

Method Description
RemovePascalDelimiters ( string text, string delimiter ) : string
Singularise ( string input, NameValueCollection singularisationRules ) : string
StringUtilities ( ) : System

Method Details

AppendMessage() public static method

Appends a given message to an existing message contained in a string builder
public static AppendMessage ( StringBuilder origStringBuilder, string appendedString, string separator ) : StringBuilder
origStringBuilder StringBuilder The string builder that contains the original /// message
appendedString string The message to add on (right part)
separator string The separator to insert between the two parts
return StringBuilder

AppendMessage() public static method

Appends a given message to an existing message, inserting a new line (carriage return) between the messages
public static AppendMessage ( string origMessage, string messageToAppend ) : string
origMessage string The existing message (left part)
messageToAppend string The message to add on (right part)
return string

AppendMessage() public static method

Appends a given message to an existing message, using the given separator betweeen the two parts. Ensures that the seperator is only inserted between two appended messages. I.e. there will never be a trailing seperator.
public static AppendMessage ( string origMessage, string messageToAppend, string separator ) : string
origMessage string The existing message (left part)
messageToAppend string The message to add on (right part)
separator string The separator to insert between the two /// parts
return string

BoolTryParse() public static method

Converts a string representing a boolean in one of many formats.
/// Thrown if is . ///
public static BoolTryParse ( object valueToParse, bool &result ) : bool
valueToParse object string to be parsed
result bool the resultant parsed value if parsing was a success
return bool

Camelize() public static method

Camel cases the input, removing spaces.
public static Camelize ( string input ) : string
input string
return string

Classify() public static method

Create a classification of the input this is a Singular of the input Camel cased.
public static Classify ( string input ) : string
input string
return string

CountOccurrences() public static method

Indicates the number of times a given token appears in a string
public static CountOccurrences ( string fullText, char token ) : int
fullText string The string to search within
token char The token to search for
return int

CountOccurrences() public static method

Indicates the number of times a given token appears in a string
public static CountOccurrences ( string fullText, char token, int startIndex, int length ) : int
fullText string The string to search within
token char The token to search for
startIndex int The index of the position to start counting occurences from.
length int The length of text to count occurences from.
return int

CountOccurrences() public static method

Indicates the number of times a given string appears in a larger string
public static CountOccurrences ( string fullText, string searchText ) : int
fullText string The string to search within
searchText string The section to search for
return int

CountOccurrences() public static method

Indicates the number of times a given string appears in a larger string
public static CountOccurrences ( string fullText, string searchText, int startIndex, int length ) : int
fullText string The string to search within
searchText string The section to search for
startIndex int The index of the position to start counting occurences from.
length int The length of text to count occurences from.
return int

DelimitPascalCase() public static method

Breaks up a Pascal-cased string into sections that are divided by the given delimiter. For instance, an input string of "PascalCase" and a delimiter of " " will give "Pascal Case"
public static DelimitPascalCase ( string inputString, string delimiter ) : string
inputString string The string to delimit
delimiter string The delimiter to insert between /// sections, such as a space or comma
return string

GetLeftSection() public static method

Returns the portion of the string that is left of the given search text
public static GetLeftSection ( string fullText, string searchText ) : string
fullText string The string to search within
searchText string The section to the right of the desired /// text
return string

GetNameValueCollection() public static method

returns a NameValueCollection of nameValue Pairs for the nameValuePairString. e.g. nameValuePairString = "name=value&name2=value2&name3=value3" will return a NameValueCollection with 3 items for name, name2 and name3.
public static GetNameValueCollection ( string nameValuePairString ) : NameValueCollection
nameValuePairString string The name value pair to split.
return System.Collections.Specialized.NameValueCollection

GetRightSection() public static method

Returns the portion of the string that is right of the given search text
public static GetRightSection ( string fullText, string searchText ) : string
fullText string The string to search within
searchText string The section to the left of the desired /// text
return string

GetValueString() public static method

For a given name value pair e.g. a query string or cookie string that is formatted as name=value&name2=value2&name3=value3 etc this will return the value for a specified name e.g. for nameValuePairString = "name=value&name2=value2&name3=value3" and name = "name2" GetValueString will return value2.
public static GetValueString ( string nameValuePairString, string name ) : string
nameValuePairString string The name value pair to parse
name string The name of the name value pair for which you want the value
return string

GuidToUpper() public static method

Returns the guid as a string with a standard format of "B" and with all the characters changed to upper.
public static GuidToUpper ( System.Guid guid ) : string
guid System.Guid
return string

GuidTryParse() public static method

Converts the string representation of a Guid to its Guid equivalent. A return value indicates whether the operation succeeded.
/// Thrown if is . ///
public static GuidTryParse ( string s, System.Guid &result ) : bool
s string A string containing a Guid to convert.
result System.Guid /// When this method returns, contains the Guid value equivalent to /// the Guid contained in , if the conversion /// succeeded, or if the conversion failed. /// The conversion fails if the parameter is a /// reference ( in /// Visual Basic), or is not of the correct format. ///
return bool

Humanize() public static method

Replaces all _ with whites space
public static Humanize ( string input ) : string
input string
return string

IsManyPascalWords() public static method

Determines whether the word is already pascal cased. This will return true when.
public static IsManyPascalWords ( string text ) : bool
text string
return bool

PascalCaseTableName() public static method

Pascal Cases a table name that has as seperator '_', '-' or ' ' in it so that the the pascal casing will be done as follows first letter is capitalised the first letter that follows a seperator is capitalised. All other letters are left unchanged.
public static PascalCaseTableName ( string text ) : string
text string
return string

Pluralize() public static method

Pluralises a noun using standard rule e.g. Name => Names Pantry => Pantries.
public static Pluralize ( string input ) : string
input string
return string

RemovePrefix() public static method

Removes a prefix defined by prefix from the text if it is found to be the leading characters of text.
public static RemovePrefix ( string prefix, string text ) : string
prefix string
text string
return string

ReplaceDoubleQuotesWithTwo() public static method

Replaces double quotes with two double quotes in the given string
public static ReplaceDoubleQuotesWithTwo ( string value ) : string
value string The string to amend
return string

ReplaceSingleQuotesWithTwo() public static method

Replaces single quotes with two single quotes in the given string
public static ReplaceSingleQuotesWithTwo ( string value ) : string
value string The string to amend
return string

Singularize() public static method

Singularises the input string using heuristics and rule.
public static Singularize ( string input ) : string
input string
return string

ToLowerFirstLetter() public static method

Changes the first character to a lowercase.
public static ToLowerFirstLetter ( string input ) : string
input string
return string