StringUtil

Description

static class Tinman.Core.StringUtil

Helper class for dealing with Strings.

Public / Constants

Delegate​Compare


[ShutdownSurvive]
public static readonly attribute DelegateCompare → (CompareDelegate<string>)

The delegate for Compare.

Delegate​Equals


[ShutdownSurvive]
public static readonly attribute DelegateEquals → (EqualsDelegate<string>)

The delegate for Equals.

Delegate​Hash


[ShutdownSurvive]
public static readonly attribute DelegateHash → (HashCodeDelegate<string>)

The delegate for Hash.

Lorem​Ipsum


public constant LoremIpsum → ("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. ":string)

Some boilerplate text.

The text contains no line-breaks and a single whitespace at the end:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
sanctus est Lorem ipsum dolor sit amet.

Lorem​Ipsum​Block


public constant LoremIpsumBlock → ("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod\r\ntempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At\r\nvero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,\r\nno sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit\r\namet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut\r\nlabore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam\r\net justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata\r\nsanctus est Lorem ipsum dolor sit amet. ":string)

Some boilerplate text.

The text contains CRLF line-breaks (wrapping at 80 columns) and a single whitespace at the end:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
sanctus est Lorem ipsum dolor sit amet.

Public / Methods

Base64​Decode


[Pure]
public static method Base64Decode → (1)

base64 in : string

The base-64 string to decode.

returns → int8 [ ]

The decoded byte array or null if base64 in is null or not valid base-64.

Decodes the given base-64 string (RFC 4648).

Binary​Decode


[Pure]
public static method BinaryDecode → (1)

value in : int8 [ ]

The compressed byte array.

returns → string

The decoded string or null if value in is null.

Decodes a string from the given compressed byte array.

IOException

If the binary format of value in is invalid.

Binary​Encode


[Pure]
public static method BinaryEncode → (1)

value in : string

The string value.

returns → int8 [ ]

The compressed byte array or null if value in is null.

Encodes the given string as a compressed byte array.

Char​At


[Pure]
public static method CharAt → (3)

str in : string

The string.

index in : int32

The index.

replacement opt : char = '''\0'''

The value to return in case index in is out of the valid index range or str in is null.

returns → char

The index in-th character or replacement opt (see above).

Returns the index in-th character in the given string.

Coalesce


[Pure]
public static method Coalesce → (3)

value in : string

The input string value.

defaultValue opt : string = null

The replacement value.

isEmpty opt : bool = true

true to replace value if empty (see IsEmptyOrWhitespace), false to replace value if null.

returns → string

The resulting value.

Replaces the given value in if it is null and/or empty.

Compare


[Pure]
public static method Compare → (2)

in : string

First string value.

in : string

Second string value.

returns → int32

if in is less than in.
[=0] if in is equal to in.
[>0] if in is greater than in.

Compares the given strings.

  • null string values appear first.

  • Sort order is ascending, according to ordinal UTF-16 character value.

  • Of two strings having the same prefix, the shorter one appears first.

Compare​Char


[Pure]
public static method CompareChar → (3)

first in : char

The first character.

second in : char

The second character.

caseSensitive opt : bool = true

Do case-sensitive comparison?

returns → int32

<0 if first in is less than second in.
0 if first in is equal to second in.
>0 if first in is greater than second in.

Compares the given characters.

Compare​Part


[Pure]
public static method ComparePart → (7)

first in : string

The first string.

firstIdx in : int32

Index of substring in first in.

firstLength in : int32

Length of substring in first in.

second in : string

The second string.

secondIdx in : int32

Index of substring in second in.

secondLength in : int32

Length of substring in second in.

caseSensitive opt : bool = true

Do case-sensitive comparison?

returns → int32

<0 if first in is less than second in.
0 if first in is equal to second in.
>0 if first in is greater than second in.

Compares two substrings.

This method considers a null string to be less than a non-null one. Shorter strings are also considered less than longer ones.

Concatenate


[Pure]
public static method Concatenate → (4)

tokens in : IEnumerable<string>

[not-null]
The string tokens to concatenate.

delimiter opt : string = null

Optional delimiter token to insert between tokens.

prefix opt : string = null

Optional prefix token.

suffix opt : string = null

Optional suffix token.

returns → string

The resulting string.

Concatenates the given string tokens using the specified delimiter, prefix and suffix.

Contains​At


[Pure]
public static method ContainsAt → (3)

value in : string

[not-null]
The string to check.

offset in : int32

[0..value.Length]
Offset into value in.

part in : string

[not-null]
The string part to find in value in.

returns → bool

true if part in is contained in value in at offset in,
false if not.

Checks if the given string value in contains the given part in at the specified offset in.

Default​If​Empty


[Pure]
public static method DefaultIfEmpty → (2)

value in : string

The string value.

defaultValue in : string

The default value.

returns → string

The resulting value.

Returns the given default value if value in is null or has a length of 0.

Default​If​Empty​Or​Whitespace


[Pure]
public static method DefaultIfEmptyOrWhitespace → (2)

value in : string

The string value.

defaultValue opt : string = ""

The default value.

returns → string

The resulting value.

Returns the given default value if value in is null, has a length of 0 or contains only whitespace characters.

Default​If​Null


[Pure]
public static method DefaultIfNull → (2)

value in : string

The string value.

defaultValue opt : string = ""

The default value.

returns → string

The resulting value.

Returns the given default value if value in is null.

Equals


[Pure]
public static method Equals → (2)

in : string

First string value.

in : string

Second string value.

returns → bool

true if both string values are equal, false if not.

Checks if the given string values are equal.

This method is intended for being used as an equality delegate.

Hash


[Pure]
public static method Hash → (1)

in : string

The string value.

returns → int32

The hash code.

Computes a hash code for the given string, using HashUtil.Str.

This method is intended for being used as a hash code delegate.

Is​Empty


[Pure]
public static method IsEmpty → (1)

value in : string

The string.

returns → bool

true if value in is empty, false if not.

Checks if the given string is empty.

A string is considered empty if it is null or has a length or 0.

Is​Empty​Or​Whitespace


[Pure]
public static method IsEmptyOrWhitespace → (1)

value in : string

The string.

returns → bool

true if value in is empty or whitespace., false if not.

Checks if the given string is empty or whitespace.

A string is considered empty or whitespace. if it is null, has a length or 0 or contains only whitespace characters.

Minimum​Valid​Index


[Pure]
public static method MinimumValidIndex → (2)

in : int32

First index value.

in : int32

Second index value.

returns → int32

The minimum valid index.

Returns the minimum valid (i.e. non-negative) string index value.

Number​Format


[Pure]
public static method NumberFormat → (3)

value in : float64

The number to format (must neither be infinity nor not-a-number).

single in : bool

Format as single precision (true) or double precision (false)?

parseable in : bool

Format using roundtrip precision (i.e. the formatted value can be parsed back without loss of information)?

returns → string

The formatted number string.

Formats the given floating-point number as a decimal string.

Number​Parse


[Pure]
public static method NumberParse → (1)

value in : string

The value to parse.

returns → float64

The parsed value or Maths.NanD if value in is not a valid number string.

Parses the given regular floating point number (as defined by the float rule described by Parse.ParseGrammar, excluding NaN or Inf).

Replace


[Pure]
public static method Replace → (4)

text in : string

[not-null]
The input text.

find in : string

[not-null]
The text to find and replace.

replace opt : string = ""

[not-null]
The replacement text.

offset opt : int32 = 0

[0..text.Length]
Offset into text in.

returns → string

The resulting string.

Replaces all occurrences of find in in text in with replace opt.

To​Camel​Case


[Pure]
public static method ToCamelCase → (1)

name in : string

[not-null]
The input name.

returns → string

The camel case name.

Generates a camel case name from the given input:
'SOME_NAME_WITH_UNDERSCORES' => 'SomeNameWithUnderscores'

To​Chars


public static method ToChars → (3)

value in : string

[not-null]
The input string.

offset opt : int32 = 0

[0..value.Length]
Offset into value in.

length opt : int32 = -1

[-1..value.Length-offset]
Number of characters to copy or -1 to copy all characters in value in from offset opt.

returns → char [ ]

The output character sequence.

Returns a character sequence for the given string.

To​Hex​B


[Pure]
public static method ToHexB → (1)

value in : int8

The value.

returns → string

The hexadecimal number string.

Returns a hexadecimal number string for the given 8-bit integer value.

To​Hex​I


[Pure]
public static method ToHexI → (1)

value in : int32

The value.

returns → string

The hexadecimal number string, without 0x prefix.

Returns a hexadecimal number string for the given 32-bit integer value.

To​Hex​L


[Pure]
public static method ToHexL → (1)

value in : int64

The value.

returns → string

The hexadecimal number string, without 0x prefix.

Returns a hexadecimal number string for the given 64-bit integer value.

To​Hex​S


[Pure]
public static method ToHexS → (1)

value in : int16

The value.

returns → string

The hexadecimal number string, without 0x prefix.

Returns a hexadecimal number string for the given 16-bit integer value.

To​Lower

2 overloads


[Pure]
public static method ToLower1 → (1)

in : char

The character.

returns → char

The lowercase character.

Returns the culture-invariant lowercase of the given character.


[Pure]
public static method ToLower2 → (1)

in : string

The string.

returns → string

The lowercase string or null iff in is null.

Returns the culture-invariant lowercase of the given string.

To​Lower​First


[Pure]
public static method ToLowerFirst → (1)

str in : string

The string.

returns → string

The resulting string.

Converts the first character of the given string to lower-case.

To​String


[Pure]
public static method ToString → (3)

array in : char [ ]

[not-null]
The input character array.

offset opt : int32 = 0

[0..array.Length]
Offset into array in.

length opt : int32 = -1

[-1..array.Length-offset]
Number of characters to copy or -1 to copy all characters in array in from offset opt.

returns → string

The output string.

Returns a string from the given character sequence.

To​Upper

2 overloads


[Pure]
public static method ToUpper1 → (1)

in : char

The character.

returns → char

The uppercase character.

Returns the culture-invariant uppercase of the given character.


[Pure]
public static method ToUpper2 → (1)

in : string

The string.

returns → string

The uppercase string or null iff in is null.

Returns the culture-invariant uppercase of the given string.

To​Upper​First


[Pure]
public static method ToUpperFirst → (1)

str in : string

The string.

returns → string

The resulting string.

Converts the first character of the given string to upper-case.

Trim


[Pure]
public static method Trim → (2)

value in : string

[not-null]
The string value to trim.

how opt : int32 = 0

< 0 : trim only leading whitespace,
= 0 : trim leading and trailing whitespace,
> 0 : trim trailing whitespace

returns → RangeI

The trimmed character range in value in.

Trims leading and/or trailing whitespace characters.

Unique​Tag


[Pure]
public static method UniqueTag → ()

returns → string

The unique string tag.

Returns a string tag (4 letters or digits) that is pseudo-unique (the tag sequence will repeat after 1679616 elements) in the calling process.