Class StringExtensions
Class encapsulating extension for String class.
Inheritance
Namespace: Sartorius.SAF.Extensions
Assembly: Sartorius.SAF.dll
Syntax
public static class StringExtensions
Methods
View SourceIsHexColor(String)
Determines whether this value is convertible to a hexadecimal color.
Declaration
public static bool IsHexColor(this string hexValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | hexValue | The hexadecimal value. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsStringHex(String)
Determines whether the given string is a valid hexadecimal value
Declaration
public static bool IsStringHex(this string hexString)
Parameters
Type | Name | Description |
---|---|---|
System.String | hexString | A string that potentially contains a hex value. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Replace(String, String, String, Int32)
Replaces the oldValue
with the newValue
starting at selectionStart
.
Declaration
public static string Replace(this string str, string oldValue, string newValue, int selectionStart)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string. |
System.String | oldValue | The old value. |
System.String | newValue | The new value. |
System.Int32 | selectionStart | Start of the selection. |
Returns
Type | Description |
---|---|
System.String | Returns a new System.String in which the |
Search(String, String)
Returns a value indicating whether the specified String object occurs within this string using a wildcard search and the current culture for lexical comparison.
Declaration
[Pure]
public static bool Search(this string str, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string. |
System.String | value | The value to search. This may contain wildcards, see examples |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
This method performs a case sensitive lexical search according to the System.Globalization.CultureInfo.CurrentCulture. The search begins at the first character position of this string and continues through the last character position.
If value
contains a wildcard pattern, the pattern is searched in str
, see examples. Otherwise this method only returns true if the string starts with the value
.
Valid wildcard patterns are ?
to match zero or exactly one character and *
to match zero or more characters.
Examples
This example illustrates how to use the Search(String, String) extension
// Search pattern = Test* -> returns true if the string starts with "Test".
var stringStartsWith = "TestString".Search("Test*");
This example illustrates how to use the Search(String, String) extension
// Search pattern = *ing -> returns true if the string ends with "ing".
var stringEndsWith = "TestString".Search("*ing");
This example illustrates how to use the Search(String, String) extension
// Search pattern = *stS* -> returns true if the string contains with "stS".
var stringContains = "TestString".Search("*stS*");
View Source
Search(String, String, StringComparison)
Returns a value indicating whether the specified String object occurs within this string using a wildcard search using the specified System.StringComparison.
Declaration
[Pure]
public static bool Search(this string str, string value, StringComparison comparison)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string. |
System.String | value | The value to search. |
System.StringComparison | comparison | The System.StringComparison used for comparing. See remarks for further information. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
This method performs a comparison according to the provided comparison
. The search begins at the first character position of this string and continues through the last character position.
If value
contains a wildcard pattern, the pattern is searched in str
, see examples. Otherwise this method only returns true if the string starts with the value
.
Valid wildcard patterns are ?
to match zero or exactly one character and *
to match zero or more characters.
When using System.StringComparison.Ordinal or System.StringComparison.OrdinalIgnoreCase the search does not use wildcard patterns.
Examples
This example illustrates how to use the Search(String, String) extension
// Search pattern = test* -> returns true if the string starts with "test", ignore case.
var stringStartsWith = "TestString".Search("test*", StringComparison.InvariantCultureIgnoreCase);
This example illustrates how to use the Search(String, String) extension
// Search pattern = *iNg -> returns true if the string ends with "ing", ignore case.
var stringEndsWith = "TestString".Search("*iNg", StringComparison.InvariantCultureIgnoreCase);
This example illustrates how to use the Search(String, String) extension
// Search pattern = *stS* -> returns true if the string contains with "ESTS", ignore case.
var stringContains = "TestString".Search("*ESTS*", StringComparison.InvariantCultureIgnoreCase);