Joutsen  v0.4.1
Static Public Member Functions | List of all members
Joutsen.System.StringExtensions Class Reference

A static class containing extensions for the String class. More...

Static Public Member Functions

static string FormatWith (this string format, Map< String, Object > values)
 An extension method that formats a String with named placeholders. More...
 
static string FormatWith (this string format, object values)
 An extension method that formats a String with named placeholders. More...
 
static string FormatWith (this string format, params object[] values)
 An extension method that formats a String with named placeholders. More...
 
static bool StartsWithAny (this string value, SCG.IEnumerable< String > prefixes)
 Checks if a String starts with one of a list of substrings. More...
 
static bool StartsWithAny (this string value, SCG.IEnumerable< String > prefixes, StringComparison option)
 Checks if a String starts with one of a list of substrings. More...
 
static bool EndsWithChar (this string value, char c, StringComparison comparison)
 Checks if value ends with the character provided by c taking the comparison options into account. More...
 
static bool EndsWithChar (this string value, char c)
 Checks if value ends exactly with the character provided by c. More...
 
static String ReplaceMany (this String input, SCG.IEnumerable< Tuple< String, String >> replacements)
 Replaces all the occurences of keys of replacements in input with the corresponding values. More...
 
static String ReplaceMany (this String input, SCG.IEnumerable< SCG.KeyValuePair< String, String >> replacements)
 Replaces all the occurences of keys of replacements in input with the corresponding values. More...
 
static String ReplaceMany (this String input, SCG.IEnumerable< Tuple< Char, Char >> replacements)
 Replaces all the occurences of keys of replacements in input with the corresponding values. More...
 
static String ReplaceMany (this String input, SCG.IEnumerable< SCG.KeyValuePair< Char, Char >> replacements)
 Replaces all the occurences of keys of replacements in input with the corresponding values. More...
 
static String ConvertCharToLowerCase (this String value, int charIndex)
 Converts a single character in a String to lower case. More...
 
static String ConvertCharToUpperCase (this String value, int charIndex)
 Converts a single character in a String to upper case. More...
 
static bool IsNumeric (this String stringValue)
 Checks if a string contains only of number characters. More...
 
static String NormalizeToNonCombining (this String stringValue)
 Normalizes the string to a form that does no longer include combining characters like Umlaute or Accents. More...
 
static String NormalizeForSearch (this String stringValue)
 Normalizes the string to a form that does no longer include diacritics or special characters. More...
 

Detailed Description

A static class containing extensions for the String class.

Since
0.0.1

Member Function Documentation

◆ ConvertCharToLowerCase()

static String Joutsen.System.StringExtensions.ConvertCharToLowerCase ( this String  value,
int  charIndex 
)
static

Converts a single character in a String to lower case.

Parameters
valuethe String value to modify
charIndexthe index of the character in value that is to be converted
Returns
a new instance of String with a lower case character at charIndex
Exceptions
System.ArgumentExceptionif charIndex is smaller than zero or bigger than the input value
Remarks
if the character at charIndex is already in lower case or is not a letter that can be converted to lower case the unmodified value is returned.
Since
0.2.0

◆ ConvertCharToUpperCase()

static String Joutsen.System.StringExtensions.ConvertCharToUpperCase ( this String  value,
int  charIndex 
)
static

Converts a single character in a String to upper case.

Parameters
valuethe String value to modify
charIndexthe index of the character in value that is to be converted
Returns
a new instance of String with a upper case character at charIndex
Exceptions
System.ArgumentExceptionif charIndex is smaller than zero or bigger than the input value
Remarks
if the character at charIndex is already in upper case or is not a letter that can be converted to upper case the unmodified value is returned.
Since
0.2.0

◆ EndsWithChar() [1/2]

static bool Joutsen.System.StringExtensions.EndsWithChar ( this string  value,
char  c,
StringComparison  comparison 
)
static

Checks if value ends with the character provided by c taking the comparison options into account.

Parameters
valuethe String value whose last character is to be checked
cthe character to check for
comparisonoptions for the comparison of the characters
Returns
true if the last character of value value matches c, otherwise false
Since
0.2.0

◆ EndsWithChar() [2/2]

static bool Joutsen.System.StringExtensions.EndsWithChar ( this string  value,
char  c 
)
static

Checks if value ends exactly with the character provided by c.

Parameters
valuethe String value whose last character is to be checked
cthe character to check for
Returns
true if the last character of value is c, otherwise false
Since
0.2.0

◆ FormatWith() [1/3]

static string Joutsen.System.StringExtensions.FormatWith ( this string  format,
Map< String, Object >  values 
)
static

An extension method that formats a String with named placeholders.

Parameters
formatThe format String containing named placeholders
valuesPairs of name and value where each name is a placeholder that will be replaced with the corresponding value
Returns
The formatted String
Remarks
The format System.String can contain placeholders in the form of "{<name>}" which will be replaced by the value in the values dictionary that is associated with the key <name>. All additional formats that supported by System.String.Format are supported.

◆ FormatWith() [2/3]

static string Joutsen.System.StringExtensions.FormatWith ( this string  format,
object  values 
)
static

An extension method that formats a String with named placeholders.

Parameters
formatThe format String containing named placeholders
valuesAn System.Object where each property name used as a placeholder in the format String will be replaced with the properties value
Returns
The formatted String
Remarks
The format String can contain placeholders in the form of "{<name>}" which will be replaced by the value of the values object's property <name>. All additional formats that are supported by System.String.Format are supported.

◆ FormatWith() [3/3]

static string Joutsen.System.StringExtensions.FormatWith ( this string  format,
params object []  values 
)
static

An extension method that formats a String with named placeholders.

Parameters
formatThe format String containing named placeholders
valuesThe objects that are filled into the format string according to their index in the array
Returns
The formatted String
Remarks
This is a shorthand extension method for System.String.Format.

◆ IsNumeric()

static bool Joutsen.System.StringExtensions.IsNumeric ( this String  stringValue)
static

Checks if a string contains only of number characters.

Since
0.4.0

◆ NormalizeForSearch()

static String Joutsen.System.StringExtensions.NormalizeForSearch ( this String  stringValue)
static

Normalizes the string to a form that does no longer include diacritics or special characters.

Remarks
Even though it is meant to normalize terms to use in a text search, it does not change the case of the string.
Since
0.4.0

◆ NormalizeToNonCombining()

static String Joutsen.System.StringExtensions.NormalizeToNonCombining ( this String  stringValue)
static

Normalizes the string to a form that does no longer include combining characters like Umlaute or Accents.

Remarks
This method is not able to normalize combined characters like æ or œ because they are one character.
Since
0.4.0

◆ ReplaceMany() [1/4]

static String Joutsen.System.StringExtensions.ReplaceMany ( this String  input,
SCG.IEnumerable< Tuple< String, String >>  replacements 
)
static

Replaces all the occurences of keys of replacements in input with the corresponding values.

Parameters
inputthe String whose substrings will be replaced
replacementsa list of replacements as tuples where the first value is the match that is searched for in in input and the second value is the replacement for that substring
Returns
the input String with all substrings defined by replacements replaced
Exceptions
System.ArgumentNullExceptionif input, replacements or one of the keys or values in replacements is null
Remarks
Entries in replacements will be processed sequntially, replacing all occurences of one entry at a time before replacing occurences of the next entry. This can lead to side effects if the replacements also match the keys of later entries. It is also possible to use the same key twice which might cause the second occurence to have no effect at all. The caller needs to take care of these side effects.
Since
0.2.0

◆ ReplaceMany() [2/4]

static String Joutsen.System.StringExtensions.ReplaceMany ( this String  input,
SCG.IEnumerable< SCG.KeyValuePair< String, String >>  replacements 
)
static

Replaces all the occurences of keys of replacements in input with the corresponding values.

Parameters
inputthe String whose substrings will be replaced
replacementsa list of replacements as key value pairs where the key is the match that is searched for in in input and the second value is the replacement for that substring
Returns
the input String with all substrings defined by replacements replaced
Exceptions
System.ArgumentNullExceptionif input, replacements or one of the keys or values in replacements is null
Remarks
Entries in replacements will be processed sequntially, replacing all occurences of one entry at a time before replacing occurences of the next entry. This can lead to side effects if the replacements also match the keys of later entries. It is also possible to use the same key twice which might cause the second occurence to have no effect at all. The caller needs to take care of these side effects.
Since
0.2.0

◆ ReplaceMany() [3/4]

static String Joutsen.System.StringExtensions.ReplaceMany ( this String  input,
SCG.IEnumerable< Tuple< Char, Char >>  replacements 
)
static

Replaces all the occurences of keys of replacements in input with the corresponding values.

Parameters
inputthe String whose substrings will be replaced
replacementsa list of replacements as tuples where the first value is the match that is searched for in in input and the second value is the replacement for that character
Returns
the input String with all characters defined by replacements replaced
Exceptions
System.ArgumentNullExceptionif input, replacements or one of the keys or values in replacements is null
Remarks
Entries in replacements will be processed sequntially, replacing all occurences of one entry at a time before replacing occurences of the next entry. This can lead to side effects if the replacements also match the keys of later entries. It is also possible to use the same key twice which might cause the second occurence to have no effect at all. The caller needs to take care of these side effects.
Since
0.2.0

◆ ReplaceMany() [4/4]

static String Joutsen.System.StringExtensions.ReplaceMany ( this String  input,
SCG.IEnumerable< SCG.KeyValuePair< Char, Char >>  replacements 
)
static

Replaces all the occurences of keys of replacements in input with the corresponding values.

Parameters
inputthe String whose characters will be replaced
replacementsa list of replacements as key value pairs where the key is the match that is searched for in in input and the second value is the replacement for that character
Returns
the input String with all characters defined by replacements replaced
Exceptions
System.ArgumentNullExceptionif input, replacements or one of the keys or values in replacements is null
Remarks
Entries in replacements will be processed sequntially, replacing all occurences of one entry at a time before replacing occurences of the next entry. This can lead to side effects if the replacements also match the keys of later entries. It is also possible to use the same key twice which might cause the second occurence to have no effect at all. The caller needs to take care of these side effects.
Since
0.2.0

◆ StartsWithAny() [1/2]

static bool Joutsen.System.StringExtensions.StartsWithAny ( this string  value,
SCG.IEnumerable< String >  prefixes 
)
static

Checks if a String starts with one of a list of substrings.

Parameters
valueThe String that is checked for prefixes
prefixesA number of Strings that value is checked for
Returns
true if one of the Strings in prefixes is the substring that value starts with, otherwise false
Since
0.2.0

◆ StartsWithAny() [2/2]

static bool Joutsen.System.StringExtensions.StartsWithAny ( this string  value,
SCG.IEnumerable< String >  prefixes,
StringComparison  option 
)
static

Checks if a String starts with one of a list of substrings.

Parameters
valueThe String that is checked for prefixes
prefixesA number of Strings that value is checked for
optionOptions for the comparison of the prefix Strings
Returns
true if one of the Strings in prefixes is the substring that value starts with, otherwise false
Since
0.2.0