Table of Contents

Class StringUtil

Namespace
Vintagestory.API.Util
Assembly
VintagestoryAPI.dll
public static class StringUtil
Inheritance
StringUtil
Inherited Members

Methods

CompareOrdinal(string, string)

This should be used for every string comparison when ordering strings (except possibly in localised output to the user) in order to avoid any culture specific string comparison issues in certain languages (worst in the Thai language which has no spaces and treats punctuation marks as invisible)
See also: https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings

public static int CompareOrdinal(this string a, string b)

Parameters

a string
b string

Returns

int

ContainsFast(string, char)

public static bool ContainsFast(this string value, char reference)

Parameters

value string
reference char

Returns

bool

ContainsFast(string, string)

public static bool ContainsFast(this string value, string reference)

Parameters

value string
reference string

Returns

bool

CountChars(string, char)

public static int CountChars(this string text, char c)

Parameters

text string
c char

Returns

int

EndsWithOrdinal(string, string)

IMPORTANT! This method should be used for every EndsWith operation in our code (except possibly in localised output to the user). This is important in order to avoid any culture-specific different results even when examining strings in English, when the user machine's current culture is a different language (Known issue in the Thai language which has no spaces and treats punctuation marks as invisible, see https://github.com/dotnet/runtime/issues/59120)
See also: https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings

public static bool EndsWithOrdinal(this string a, string b)

Parameters

a string
b string

Returns

bool

EqualsFast(string, string)

public static bool EqualsFast(this string value, string reference)

Parameters

value string
reference string

Returns

bool

FastStartsWith(string, string, int)

public static bool FastStartsWith(string value, string reference, int len)

Parameters

value string
reference string
len int

Returns

bool

GetNonRandomizedHashCode(string)

public static int GetNonRandomizedHashCode(this string str)

Parameters

str string

Returns

int

IndexOfOrdinal(string, string)

IMPORTANT! This method should be used for every IndexOf operation in our code (except possibly in localised output to the user). This is important in order to avoid any culture-specific different results even when indexing GLSL shader code or other code strings, etc., or other strings in English, when the current culture is a different language (Known issue in the Thai language which has no spaces and treats punctuation marks as invisible, see https://github.com/dotnet/runtime/issues/59120)
See also: https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings

public static int IndexOfOrdinal(this string a, string b)

Parameters

a string
b string

Returns

int

RemoveFileEnding(string)

public static string RemoveFileEnding(this string text)

Parameters

text string

Returns

string

StartsWithFast(string, string)

public static bool StartsWithFast(this string value, string reference)

Parameters

value string
reference string

Returns

bool

StartsWithFast(string, string, int)

public static bool StartsWithFast(this string value, string reference, int offset)

Parameters

value string
reference string
offset int

Returns

bool

StartsWithOrdinal(string, string)

IMPORTANT! This method should be used for every StartsWith operation in our code (except possibly in localised output to the user). This is important in order to avoid any culture-specific different results even when examining strings in English, when the user machine's current culture is a different language (Known issue in the Thai language which has no spaces and treats punctuation marks as invisible, see https://github.com/dotnet/runtime/issues/59120)
See also: https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings

public static bool StartsWithOrdinal(this string a, string b)

Parameters

a string
b string

Returns

bool

ToBool(string, bool)

public static bool ToBool(this string text, bool defaultValue = false)

Parameters

text string
defaultValue bool

Returns

bool

ToDouble(string, double)

public static double ToDouble(this string text, double defaultValue = 0)

Parameters

text string
defaultValue double

Returns

double

ToDoubleOrNull(string, double?)

public static double? ToDoubleOrNull(this string text, double? defaultValue = 0)

Parameters

text string
defaultValue double?

Returns

double?

ToFloat(string, float)

public static float ToFloat(this string text, float defaultValue = 0)

Parameters

text string
defaultValue float

Returns

float

ToFloatOrNull(string, float?)

public static float? ToFloatOrNull(this string text, float? defaultValue = 0)

Parameters

text string
defaultValue float?

Returns

float?

ToInt(string, int)

public static int ToInt(this string text, int defaultValue = 0)

Parameters

text string
defaultValue int

Returns

int

ToLong(string, long)

public static long ToLong(this string text, long defaultValue = 0)

Parameters

text string
defaultValue long

Returns

long

ToSearchFriendly(string)

Removes diacritics and replaces quotation marks, guillemets and brackets with a blank space. Used to create a search friendly term

public static string ToSearchFriendly(this string stIn)

Parameters

stIn string

Returns

string

UcFirst(string)

Convert the first character to an uppercase one

public static string UcFirst(this string text)

Parameters

text string

Returns

string