NamespaceSystemLibrary.Common.Net.Extensions SystemLibrary.Common.Net.dll
String Builder extensions
StringBuilderExtensions
public static class StringBuilderExtensions
Inheritance
Examples
Arguments
Methods
Check if stringbuilder ends with a certain text
public static bool EndsWith(this StringBuilder stringBuilder, string ending, bool caseInsensitive = false)
Methods arguments
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | stringBuilder | |
System.String | ending | |
System.Boolean | caseInsensitive |
Type | Description |
---|---|
System.Boolean | True or false |
Replaces " with " and ' with a single quote within the StringBuilder
Throws on null argument
public static StringBuilder HtmlDecodeQuotes(this StringBuilder html, Dictionary<string, string> additionalReplacements = null)
Methods arguments
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | html | |
System.Collections.Generic.Dictionary<System.String, System.String> | additionalReplacements |
Type | Description |
---|---|
System.Text.StringBuilder |
Replaces " with " and single quote with ' within the StringBuilder
Throws on null argument
public static StringBuilder HtmlEncodeQuotes(this StringBuilder html, Dictionary<string, string> additionalReplacements = null)
Methods arguments
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | html | |
System.Collections.Generic.Dictionary<System.String, System.String> | additionalReplacements |
Type | Description |
---|---|
System.Text.StringBuilder |
Returns the index of the text within the StringBuilder
public static int IndexOf(this StringBuilder stringBuilder, string text, bool ignoreCase = false, int start = 0)
Methods arguments
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | stringBuilder | |
System.String | text | The string to find |
System.Boolean | ignoreCase | if set to |
System.Int32 | start | The starting index. |
Type | Description |
---|---|
System.Int32 | Int or -1 if not found |
Check if stringbuilder is not null and has content
public static bool Is(this StringBuilder stringBuilder)
Methods arguments
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | stringBuilder |
Type | Description |
---|---|
System.Boolean | True or false |
Check if stringbuilder is null or has no content
public static bool IsNot(this StringBuilder stringBuilder)
Methods arguments
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | stringBuilder |
Type | Description |
---|---|
System.Boolean | True or false |
Reduce the string builder to a fixed max length
Does nothing if stringbuilder is null or less than or equal to the max length specified
Remarks
Does not throw Returns null if null was input
public static StringBuilder MaxLength(this StringBuilder stringBuilder, int maxLength)
var sb = new StringBuilder("hello world");
sb.MaxLength(1);
var text = sb.ToString();
// text == "h"
Methods arguments
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | stringBuilder | |
System.Int32 | maxLength | Max amount of characters to keep |
Type | Description |
---|---|
System.Text.StringBuilder |
Check if stringbuilder ends with certain texts, if so, the first ending match was removed
public static bool TrimEnd(this StringBuilder stringBuilder, params string[] values)
Methods arguments
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | stringBuilder | |
System.String[] | values |
Type | Description |
---|---|
System.Boolean | True if text was removed, else false |
}