Repository navigation
OnixLabs.Core.Text.StringBuilderExtensions
Provides extension methods for StringBuilder instances, complementing the built-in Append/Insert API with prepend, trim, and wrap operations. Every method returns the same StringBuilder instance, enabling fluent chaining.
| Namespace | OnixLabs.Core.Text |
| Assembly | OnixLabs.Core.dll (NuGet) |
| Inheritance |
object → StringBuilderExtensions
|
[EditorBrowsable(EditorBrowsableState.Never)]
public static class StringBuilderExtensionsNote This class is decorated with
[EditorBrowsable(EditorBrowsableState.Never)], which hides it from IntelliSense completion lists in some IDE configurations. The extension methods remain fully public and callable; they primarily support the Base value codecs and other internal text formatting throughout the library.
StringBuilderExtensions fills gaps in the standard StringBuilder API. All methods return the receiver (this StringBuilder) to support fluent chaining. The Trim family removes repeated leading or trailing occurrences; the Wrap family is a thin convenience around Prepend + Append; and the params-based Append / Prepend overloads delegate to AppendJoin / PrependJoin with an empty separator, so elements are concatenated without any delimiter.
Bring the methods into scope with:
using OnixLabs.Core.Text;| Method | Returns | Description |
|---|---|---|
Append(params object[]) |
StringBuilder |
Appends the specified values with no separator. |
Prepend(object) |
StringBuilder |
Prepends the specified object value. |
Prepend(char) |
StringBuilder |
Prepends the specified char value. |
Prepend(string) |
StringBuilder |
Prepends the specified string value. |
Prepend(params object[]) |
StringBuilder |
Prepends the specified values with no separator. |
PrependJoin(string, params object?[]) |
StringBuilder |
Joins the specified values with a separator and prepends the result. |
Trim(char) |
StringBuilder |
Trims the specified char from the start and end. |
TrimStart(char) |
StringBuilder |
Trims the specified char from the start. |
TrimEnd(char) |
StringBuilder |
Trims the specified char from the end. |
Trim(string) |
StringBuilder |
Trims the specified string from the start and end. |
TrimStart(string) |
StringBuilder |
Trims the specified string from the start. |
TrimEnd(string) |
StringBuilder |
Trims the specified string from the end. |
Wrap(char, char) |
StringBuilder |
Wraps the builder between the specified start and end char values. |
Wrap(string, string) |
StringBuilder |
Wraps the builder between the specified start and end string values. |
public static StringBuilder Append(this StringBuilder receiver, params object[] values)Appends the specified values to the current StringBuilder, concatenated with no separator between elements (implemented as AppendJoin(string.Empty, values)).
| Parameter | Type | Description |
|---|---|---|
values |
object[] |
The values to append. |
Returns — The current StringBuilder with the specified values appended.
public static StringBuilder Prepend(this StringBuilder receiver, object value)Prepends the specified object value to the current StringBuilder (inserts at index 0).
| Parameter | Type | Description |
|---|---|---|
value |
object |
The value to prepend. |
Returns — The current StringBuilder with the specified value prepended.
public static StringBuilder Prepend(this StringBuilder receiver, char value)Prepends the specified char value to the current StringBuilder.
| Parameter | Type | Description |
|---|---|---|
value |
char |
The value to prepend. |
Returns — The current StringBuilder with the specified value prepended.
public static StringBuilder Prepend(this StringBuilder receiver, string value)Prepends the specified string value to the current StringBuilder.
| Parameter | Type | Description |
|---|---|---|
value |
string |
The value to prepend. |
Returns — The current StringBuilder with the specified value prepended.
public static StringBuilder Prepend(this StringBuilder receiver, params object[] values)Prepends the specified values to the current StringBuilder, concatenated with no separator between elements (implemented as PrependJoin(string.Empty, values)).
| Parameter | Type | Description |
|---|---|---|
values |
object[] |
The values to prepend. |
Returns — The current StringBuilder with the specified values prepended.
public static StringBuilder PrependJoin(this StringBuilder receiver, string separator, params object?[] values)Concatenates the string representations of the elements in values, using separator between each member, then prepends the result to the current StringBuilder.
| Parameter | Type | Description |
|---|---|---|
separator |
string |
The string to use as a separator. separator is included in the joined string only if values has more than one element. |
values |
object?[] |
An array containing the values to concatenate and prepend. |
Returns — The current StringBuilder with the specified values joined and prepended.
public static StringBuilder Trim(this StringBuilder receiver, char value)Trims the specified char value from the start and end of the current StringBuilder.
| Parameter | Type | Description |
|---|---|---|
value |
char |
The char value to trim. |
Returns — The current StringBuilder with the specified char value trimmed from the start and end.
public static StringBuilder TrimStart(this StringBuilder receiver, char value)Trims the specified char value from the start of the current StringBuilder. Removes leading occurrences repeatedly until the first character no longer matches value.
| Parameter | Type | Description |
|---|---|---|
value |
char |
The char value to trim. |
Returns — The current StringBuilder with the specified char value trimmed from the start.
public static StringBuilder TrimEnd(this StringBuilder receiver, char value)Trims the specified char value from the end of the current StringBuilder. Removes trailing occurrences repeatedly until the last character no longer matches value.
| Parameter | Type | Description |
|---|---|---|
value |
char |
The char value to trim. |
Returns — The current StringBuilder with the specified char value trimmed from the end.
public static StringBuilder Trim(this StringBuilder receiver, string value)Trims the specified string value from the start and end of the current StringBuilder.
| Parameter | Type | Description |
|---|---|---|
value |
string |
The string value to trim. |
Returns — The current StringBuilder with the specified string value trimmed from the start and end.
public static StringBuilder TrimStart(this StringBuilder receiver, string value)Trims the specified string value from the start of the current StringBuilder. Removes leading occurrences repeatedly until the builder no longer begins with value. If value is null or empty, the builder is returned unchanged.
| Parameter | Type | Description |
|---|---|---|
value |
string |
The string value to trim. |
Returns — The current StringBuilder with the specified string value trimmed from the start.
public static StringBuilder TrimEnd(this StringBuilder receiver, string value)Trims the specified string value from the end of the current StringBuilder. Removes trailing occurrences repeatedly until the builder no longer ends with value. If value is null or empty, the builder is returned unchanged.
| Parameter | Type | Description |
|---|---|---|
value |
string |
The string value to trim. |
Returns — The current StringBuilder with the specified string value trimmed from the end.
public static StringBuilder Wrap(this StringBuilder receiver, char start, char end)Wraps the current StringBuilder between the specified start and end char values, prepending start and appending end.
| Parameter | Type | Description |
|---|---|---|
start |
char |
The char value to prepend. |
end |
char |
The char value to append. |
Returns — The current StringBuilder wrapped between the specified start and end char values.
public static StringBuilder Wrap(this StringBuilder receiver, string start, string end)Wraps the current StringBuilder between the specified start and end string values, prepending start and appending end.
| Parameter | Type | Description |
|---|---|---|
start |
string |
The string value to prepend. |
end |
string |
The string value to append. |
Returns — The current StringBuilder wrapped between the specified start and end string values.
using OnixLabs.Core.Text;
using System.Text;
var builder = new StringBuilder("value");
builder.Wrap('[', ']'); // "[value]"
builder.Trim('[').Trim(']'); // "value"
builder.Prepend("key="); // "key=value"
builder.Append(1, 2, 3); // "key=value123"ONIXLabs .NET Library · Repository · NuGet · License (Apache-2.0)
Copyright © ONIXLabs 2020. Licensed under the Apache License, Version 2.0.
- Enumeration<T>
- Optional<T>
- OptionalEqualityComparer<T>
- OptionalExtensions
- Result
- Result<T>
- ResultEqualityComparer<T>
- ResultExtensions
- Specification<T>
- Preconditions
- IValueEquatable<T>
- IValueComparable<T>
- IBinaryConvertible
- ISpanBinaryConvertible
- IMemoryBinaryConvertible
- ArrayExtensions
- ComparableExtensions
- DateTimeExtensions
- ISpanParsableExtensions
- ObjectExtensions
- RandomExtensions
- ReadOnlySequenceExtensions
- ReadOnlySpanExtensions
- StringExtensions
- Base16
- Base32
- Base58
- Base64
- IBaseCodec
- IBaseValue
- IBaseValue<T>
- Base16Codec
- Base32Codec
- Base58Codec
- Base64Codec
- Base16FormatProvider
- Base32FormatProvider
- Base58FormatProvider
- Base64FormatProvider
- EncodingExtensions
- ReadOnlySpanExtensions
- StringBuilderExtensions
- BigDecimal
- BigDecimalEqualityComparer
- BigDecimalOrdinalityComparer
- NumberInfo
- NumberInfoEqualityComparer
- NumberInfoOrdinalityComparer
- Int256
- Int512
- UInt256
- UInt512
- Float128
- Float256
- GenericMath
- NumericsExtensions
- ConversionMode
- ScaleMode
- Hash
- NamedHash
- Sha3
- Sha3Hash224
- Sha3Hash256
- Sha3Hash384
- Sha3Hash512
- Sha3Shake128
- Sha3Shake256
- MerkleTree
- MerkleTree<T>
- PrivateKey
- PublicKey
- NamedPrivateKey
- NamedPublicKey
- EcdhPrivateKey
- EcdhPublicKey
- EcdsaPrivateKey
- EcdsaPublicKey
- EddsaPrivateKey
- EddsaPublicKey
- RsaPrivateKey
- RsaPublicKey
- DigitalSignature
- DigitalSignatureAndPublicKey
- Salt
- Secret
- ICryptoPrimitive<T>
- IHashable
- IEcdhPrivateKey
- IEcdsaPrivateKey
- IEddsaPrivateKey
- IRsaPrivateKey
- IPrivateKeyDerivable<T>
- IPrivateKeyExportable
- IPrivateKeyImportable<T>
- IPrivateKeyPemImportable<T>
- IPrivateKeyPkcs8Exportable
- IPrivateKeyPkcs8Importable<T>
- IPrivateKeyPkcs8PemExportable
- IPrivateKeyRawExportable
- IPrivateKeyRawImportable<T>
- IPrivateKeyRawPemExportable
- IEcdhPublicKey
- IEcdsaPublicKey
- IEddsaPublicKey
- IRsaPublicKey
- IPublicKeyExportable
- IPublicKeyImportable<T>
- IPublicKeyPemExportable
- IPublicKeyPemImportable<T>
- IPublicKeyRawExportable
- IPublicKeyRawImportable<T>
- HashAlgorithmExtensions
- ReadOnlySpanExtensions