C# Class CK.Text.StringAndStringBuilderExtension

Defines useful extension methods on string and StringBuilder.
Datei anzeigen Open project: Invenietis/ck-core

Public Methods

Method Description
Append ( this @this, string s, int repeatCount ) : StringBuilder

Appends multiple time the same string.

AppendMultiLine ( this @this, string prefix, string text, bool prefixOnFirstLine, bool prefixLastEmptyLine = false ) : StringBuilder

Appends a block of text to this StringBuilder with a prefix on each line. b.AppendMultiLine( prefix, text, false, true ) is the same as the naive approach, that is to add text.Replace( Environment.NewLine, Environment.NewLine + prefix ). This method is faster (in release build), normalizes EOL (\n, \r and \r\n) to Environment.NewLine and offer a better and easier control with its parameters prefixOnFirstLine and prefixLastEmptyLine.

AppendStrings ( this @this, IEnumerable strings, string separator = ", " ) : StringBuilder

Appends a set of strings with an internal separator. (This should be named 'Append' but appropriate overload is not always detected by the compiler.)

Concatenate ( this @this, string separator = ", " ) : string

Concatenates multiple strings with an internal separator.

HexDigitValue ( this c ) : int

Gets the value (0...15) for this character ('0'...'9', 'a'...'f' or 'A.'..'F'), or -1 if this is not an hexadecimal digit.

NormalizeEOL ( this @this ) : string

Returns a string where \r\n or \n alone are normalized to Environment.NewLine.

NormalizeEOLToCRLF ( this @this ) : string

Returns a string where \n alone are normalized to \r\n.

NormalizeEOLToLF ( this @this ) : string

Returns a string where \r\n are normalized to \n.

Method Details

Append() public static method

Appends multiple time the same string.
public static Append ( this @this, string s, int repeatCount ) : StringBuilder
@this this
s string The string to repeat. Can be null.
repeatCount int The number of repetition.
return StringBuilder

AppendMultiLine() public static method

Appends a block of text to this StringBuilder with a prefix on each line. b.AppendMultiLine( prefix, text, false, true ) is the same as the naive approach, that is to add text.Replace( Environment.NewLine, Environment.NewLine + prefix ). This method is faster (in release build), normalizes EOL (\n, \r and \r\n) to Environment.NewLine and offer a better and easier control with its parameters prefixOnFirstLine and prefixLastEmptyLine.
public static AppendMultiLine ( this @this, string prefix, string text, bool prefixOnFirstLine, bool prefixLastEmptyLine = false ) : StringBuilder
@this this
prefix string The prefix to add. When null or empty, the text is appended as-is.
text string The multiple lines text to append. Can be null or empty.
prefixOnFirstLine bool True to append the prefix to the first line. False to skip this first prefix.
prefixLastEmptyLine bool /// True to append the prefix to the last empty line (when the text ends with an EOL). /// By default, when text ends with a EOL, it is ignored. ///
return StringBuilder

AppendStrings() public static method

Appends a set of strings with an internal separator. (This should be named 'Append' but appropriate overload is not always detected by the compiler.)
public static AppendStrings ( this @this, IEnumerable strings, string separator = ", " ) : StringBuilder
@this this
strings IEnumerable Set of strings. Can be null.
separator string The separator string.
return StringBuilder

Concatenate() public static method

Concatenates multiple strings with an internal separator.
public static Concatenate ( this @this, string separator = ", " ) : string
@this this
separator string The separator string.
return string

HexDigitValue() public static method

Gets the value (0...15) for this character ('0'...'9', 'a'...'f' or 'A.'..'F'), or -1 if this is not an hexadecimal digit.
public static HexDigitValue ( this c ) : int
c this This character.
return int

NormalizeEOL() public static method

Returns a string where \r\n or \n alone are normalized to Environment.NewLine.
public static NormalizeEOL ( this @this ) : string
@this this
return string

NormalizeEOLToCRLF() public static method

Returns a string where \n alone are normalized to \r\n.
public static NormalizeEOLToCRLF ( this @this ) : string
@this this
return string

NormalizeEOLToLF() public static method

Returns a string where \r\n are normalized to \n.
public static NormalizeEOLToLF ( this @this ) : string
@this this
return string