Class StringHelper
Provides helper functions for working with strings.
Inherited Members
Namespace: Nevatech.Vsb.Repository
Assembly: Nevatech.Vsb.Repository.dll
Syntax
public static class StringHelper
Methods
GetTagSize(Int32, String, Boolean)
Returns approximate size of XML tag containing a string value. Assumption is that UTF-8 encoding and English language are used.
Declaration
public static int GetTagSize(int tagNameLength, string tagValue, bool emitDefaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | tagNameLength | Length of the tag name. |
| String | tagValue | Tag value. |
| Boolean | emitDefaultValue | Indicates that default (nil) value needs to be emitted, if tag value is Null. |
Returns
| Type | Description |
|---|---|
| Int32 | Approximate size of the tag. |
Remarks
Generally tag size with value is tag name length multiplied by two plus 5 plus value size. Tag size without value is tag name plus 3. If that value is nullable and should be emitted then 13 needs to be added.
GetTagSize(Int32, String, Boolean, Boolean)
Returns approximate size of XML tag containing a string value. Assumption is that UTF-8 encoding and English language are used.
Declaration
public static int GetTagSize(int tagNameLength, string tagValue, bool emitDefaultValue, bool applyXmlEncoding)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | tagNameLength | Length of the tag name. |
| String | tagValue | Tag value. |
| Boolean | emitDefaultValue | Indicates that default (nil) value needs to be emitted, if tag value is Null. |
| Boolean | applyXmlEncoding | Indicated that string will be XML-endoded (like > symbol will be replaced with ">" characters), so its length must be adjusted for that. |
Returns
| Type | Description |
|---|---|
| Int32 | Approximate size of the tag. |
Remarks
Generally tag size with value is tag name length multiplied by two plus 5 plus value size. Tag size without value is tag name plus 3. If that value is nullable and should be emitted then 13 needs to be added.
GetTagSize<T>(Int32, T, Boolean)
Returns approximate size of XML tag containing a value-typed value. Assumption is that UTF-8 encoding and English language are used.
Declaration
public static int GetTagSize<T>(int tagNameLength, T tagValue, bool emitDefaultValue)
where T : struct, IComparable
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | tagNameLength | Length of the tag name. |
| T | tagValue | Tag value. |
| Boolean | emitDefaultValue | Indicates that default value needs to be emitted. |
Returns
| Type | Description |
|---|---|
| Int32 | Approximate size of the tag. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the tag value. |
GetTagSize<T>(Int32, Nullable<T>, Boolean)
Returns approximate size of XML tag containing a nullable value-typed value. Assumption is that UTF-8 encoding and English language are used.
Declaration
public static int GetTagSize<T>(int tagNameLength, T? tagValue, bool emitDefaultValue)
where T : struct, IComparable
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | tagNameLength | Length of the tag name. |
| Nullable<T> | tagValue | Nullable tag value. |
| Boolean | emitDefaultValue | Indicates that default value needs to be emitted. |
Returns
| Type | Description |
|---|---|
| Int32 | Approximate size of the tag. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the tag value. |
IndexOfAny(String, String[], StringComparison)
Reports the zero-based index of the first occurrence of any of the specified strings in this instance.
Declaration
public static int IndexOfAny(this string value, string[] values, StringComparison comparison)
Parameters
| Type | Name | Description |
|---|---|---|
| String | value | The string to be searched. |
| String[] | values | The strings to seek. |
| StringComparison | comparison | One of the enumeration values that specifies the rules for the search. |
Returns
| Type | Description |
|---|---|
| Int32 | The zero-based index position of value if that string is found, or -1 if it is not. |
IsEmail(String)
Checks if provided string represents a valid e-mail address.
Declaration
public static bool IsEmail(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | value | String to be examined. |
Returns
| Type | Description |
|---|---|
| Boolean | True, if provided string is not empty and represents a valid e-mail address. False, otherwise. |
NormalizeNewLines(String)
Replaces all single new line characters (\n) with pairs of carriage return + new line characters (\r\n).
Declaration
public static string NormalizeNewLines(this string value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | value | A string that needs to be normalized. |
Returns
| Type | Description |
|---|---|
| String | A normalized string. |
Replace(String, IEnumerable<Token>)
Returns a new string in which all occurrences of a specified tokens are replaced with their values.
Declaration
public static string Replace(this string source, IEnumerable<Token> values)
Parameters
| Type | Name | Description |
|---|---|---|
| String | source | A string where replacements must occur. |
| IEnumerable<Token> | values | Collection of tokens containing old and new values to be used for string replacement. |
Returns
| Type | Description |
|---|---|
| String | New string in which all occurrences of a specified tokens are replaced with their values. |
Replace(String, String, String, StringComparison)
Returns a new string in which all occurrences of a specified string in the provided source string are replaced with another specified string.
Declaration
public static string Replace(this string source, string oldValue, string newValue, StringComparison comparisonType)
Parameters
| Type | Name | Description |
|---|---|---|
| String | source | A string where replacements must occur. |
| String | oldValue | A string to be replaced. |
| String | newValue | A string to replace all occurrences of old value. |
| StringComparison | comparisonType | Specifies the rules of string comparison. |
Returns
| Type | Description |
|---|---|
| String | New string in which all occurrences of a specified string in the provided source string are replaced with another specified string. |
ToString(DateTime)
Converts DateTime value into string value.
Declaration
public static string ToString(DateTime value)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | value | Date and time value to be converted. |
Returns
| Type | Description |
|---|---|
| String | String value that represents serialized DateTime value. |
ToStringAsync(HttpRequestMessage, Boolean)
Writes HTTP request message to a string that can be used for logging purposes.
Declaration
public static Task<string> ToStringAsync(this HttpRequestMessage message, bool appendNewLines = false)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpRequestMessage | message | HTTP request message to be logged. |
| Boolean | appendNewLines | Optional flag indicating that empty lines must be added in the beginning and at the end of the result string. |
Returns
| Type | Description |
|---|---|
| Task<String> | String containing the provided HTTP request message. |
ToStringAsync(HttpResponseMessage, Boolean)
Writes HTTP response message to a string that can be used for logging purposes.
Declaration
public static Task<string> ToStringAsync(this HttpResponseMessage message, bool appendNewLines = false)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpResponseMessage | message | HTTP response message to be logged. |
| Boolean | appendNewLines | Optional flag indicating that empty lines must be added in the beginning and at the end of the result string. |
Returns
| Type | Description |
|---|---|
| Task<String> | String containing the provided HTTP response message. |
Truncate(String, Int32, String)
Truncates provided string up to specified number of characters.
Declaration
public static string Truncate(this string value, int count, string replacementSuffix)
Parameters
| Type | Name | Description |
|---|---|---|
| String | value | String that needs to be truncated. |
| Int32 | count | Maximum number of characters in the string. |
| String | replacementSuffix | String to append to the truncated string to indicate that truncation happened. |
Returns
| Type | Description |
|---|---|
| String | Provided string truncated up to specified number of characters. |