TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

class StringUtil in Tinman.Core

Helper class for dealing with Strings.

static class StringUtil  

Public / Constants

LoremIpsum

Some boilerplate text.

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. "
type string

Remarks:

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.

LoremIpsumBlock

Some boilerplate text.

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. "
type string

Remarks:

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

BinaryDecode

Decodes a string from the given compressed byte array.

[Pure]
public static method BinaryDecode (int8[] value)
type string
params value The compressed byte array.
returns The decoded string or null if value is null.

See also:

BinaryEncode

BinaryEncode

Encodes the given string as a compressed byte array.

[Pure]
public static method BinaryEncode (string value)
type int8[]
params value The string value.
returns The compressed byte array or null if value is null.

See also:

BinaryDecode

CharAt

Returns the index-th character in the given string.

[Pure]
public static method CharAt (string str, int32 index, char replacement = ''\0'')
type char
params str The string.
  index The index.
  replacement The value to return in case index is out of the valid index range or str is null. Defaults to '\0'.
returns The index-th character or replacement (see above).

Coalesce

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

[Pure]
public static method Coalesce (string value, string defaultValue = null, bool isEmpty = true)
type string
params value The input string value.
  defaultValue The replacement value. Defaults to null.
  isEmpty true to replace value if empty (see IsEmptyOrWhitespace), false to replace value if null.
returns The resulting value.

Compare

Compares the given strings.

[Pure]
public static method Compare (string a, string b)
type int32
params a First string value.
  b Second string value.
returns [<0] if a is less than b.
[=0] if a is equal to b.
[>0] if a is greater than b.

Remarks:

ComparePart

Compares two substrings.

[Pure]
public static method ComparePart (string first, int32 firstIdx, int32 firstLength, string second, int32 secondIdx, int32 secondLength, bool caseSensitive = true)
type int32
params first The first string.
  firstIdx Index of substring in first.
  firstLength Length of substring in first.
  second The second string.
  secondIdx Index of substring in second.
  secondLength Length of substring in second.
  caseSensitive Do case-sensitive comparison? Defaults to true,
returns <0 if first is less than second.
0 if first is equal to second.
>0 if first is greater than second.

Remarks:

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

Concatenate

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

[Pure]
public static method Concatenate (IEnumerable<string> tokens, string delimiter = null, string prefix = null, string suffix = null)
type string
params tokens [not-null] The string tokens to concatenate.
  delimiter Optional delimiter token to insert between tokens.
  prefix Optional prefix token.
  suffix Optional suffix token.
returns [not-null] The resulting string.

DefaultIfEmpty

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

[Pure]
public static method DefaultIfEmpty (string value, string defaultValue)
type string
params value The string value.
  defaultValue The default value.
returns The resulting value.

DefaultIfEmptyOrWhitespace

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

[Pure]
public static method DefaultIfEmptyOrWhitespace (string value, string defaultValue = " ")
type string
params value The string value.
  defaultValue The default value.
returns The resulting value.

DefaultIfNull

Returns the given default value if value is null.

[Pure]
public static method DefaultIfNull (string value, string defaultValue = " ")
type string
params value The string value.
  defaultValue The default value.
returns The resulting value.

Equals

Checks if the given string values are equal.

[Pure]
public static method Equals (string a, string b)
type bool
params a First string value.
  b Second string value.
returns true if both string values are equal, false if not.

Remarks:

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

Hash

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

[Pure]
public static method Hash (string s)
type int32
params s The string value.
returns The hash code.

Remarks:

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

IsEmpty

Checks if the given string is empty.

[Pure]
public static method IsEmpty (string value)
type bool
params value The string.
returns true if value is empty, false if not.

Remarks:

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

IsEmptyOrWhitespace

Checks if the given string is empty or whitespace.

[Pure]
public static method IsEmptyOrWhitespace (string value)
type bool
params value The string.
returns true if value is empty or whitespace., false if not.

Remarks:

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

MinimumValidIndex

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

[Pure]
public static method MinimumValidIndex (int32 a, int32 b)
type int32
params a First index value.
  b Second index value.
returns The minimum valid index.

NumberFormat

Formats the given floating-point number.

[Pure]
public static method NumberFormat (float64 value, bool single, bool parseable)
type string
params value The number to format.
  single Format as single precision (true) or double precision (false)?
  parseable Format using roundtrip precision (i.e. the formatted value can be parsed back without loss of information)?
returns [not-null] The formatted number string.

See also:

NumberParse

NumberParse

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

[Pure]
public static method NumberParse (string value)
type float64
params value The value to parse.
returns The parsed value or NanD if value is not a valid number string.

Remarks:

Number

See also:

NumberFormat

Replace

Replaces all occurrences of find in text with replace.

[Pure]
public static method Replace (string text, string find, string replace = " ", int32 offset = 0)
type string
params text [not-null] The input text.
  find [not-null] The text to find and replace.
  replace [not-null] The replacement text. Defaults to the empty string.
  offset [0..text.Length] Offset into text.
returns [not-null] The resulting string.

ToCamelCase

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

[Pure]
public static method ToCamelCase (string name)
type string
params name [not-null] The input name.
returns [not-null] The camel case name.

ToHexB

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

[Pure]
public static method ToHexB (int8 value)
type string
params value The value.
returns The hexadecimal number string.

ToHexI

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

[Pure]
public static method ToHexI (int32 value)
type string
params value The value.
returns The hexadecimal number string, without 0x prefix.

ToHexL

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

[Pure]
public static method ToHexL (int64 value)
type string
params value The value.
returns The hexadecimal number string, without 0x prefix.

ToHexS

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

[Pure]
public static method ToHexS (int16 value)
type string
params value The value.
returns The hexadecimal number string, without 0x prefix.

ToLower

Returns the culture-invariant lowercase of the given character.

[Pure]
public static method ToLower (char c)
type char
params c The character.
returns The lowercase character.

ToLowerFirst

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

[Pure]
public static method ToLowerFirst (string str)
type string
params str The string.
returns The resulting string.

ToString

Returns a string from the given character sequence.

[Pure]
public static method ToString (char[] array)
type string
params array [not-null] The input character array.
returns [not-null] The string.

Returns a string from the given character sequence.

[Pure]
public static method ToString ([] char[] array, int32 offset, int32 length)
type string
params array [not-null] The input character array.
  offset [>=0] Offset into array.
  length [>=0] Number of input tokens to convert.
returns [not-null] The string.

ToUpper

Returns the culture-invariant uppercase of the given character.

[Pure]
public static method ToUpper (char c)
type char
params c The character.
returns The uppercase character.

ToUpperFirst

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

[Pure]
public static method ToUpperFirst (string str)
type string
params str The string.
returns The resulting string.

UniqueTag

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

[Pure]
public static method UniqueTag ()
type string
returns [not-null] The unique string tag.