StringExtensions¶
Namespace:
SideXP.Core
Extension functions for string values.
Fields¶
Ascii0¶
Ascii9¶
AsciiA¶
AsciiZ¶
Asciia¶
Asciiz¶
Methods¶
Split(string, string, StringSplitOptions)¶
Polyfill for Split, which was added to Unity's base class library in Unity 2021.2 (.NET Standard 2.1). On Unity 2021.2 and newer, the built-in method is used instead.
Parameters
str: The string to split.separator: The separator to use for splitting the string.splitOptions: Eventual split options.
Returns
Returns the splitted string.
Remarks
The default options match the built-in method (None, so empty entries are kept), ensuring that splitting a string behaves identically across all supported Unity versions.
SplitLines(string, StringSplitOptions)¶
Splits a string by newline characters.
Parameters
str: The string to split.splitOptions: Eventual split options.
Returns
Returns the splitted string.
Repeat(string, int)¶
Creates a string that contains several iterations of the given input string.
Parameters
str: The string to repeat.iterations: The number of times the input string is repeated in the output.
Returns
Returns the input string repeated the given number of times.
Occurrences(string, string)¶
Counts the number of (non-overlapping) occurrences of a given substring into another string.
Parameters
str: The string in which you want to count the occurrences.pattern: The substring you want to count the occurrences of.
Returns
Returns the number of occurrences found.
Remarks
The pattern is matched literally (ordinal), not as a regular expression.
Slice(string, int)¶
Extracts a substring, from an index to another.
Parameters
str: The string you want to slice.start: The start index of the string to extract. If negative, it's used as (str.Length - start).
Returns
Returns the substring, from the given start index to the end of the string.
Slice(string, int, int)¶
Extracts a substring, from an index to another.
Parameters
str: The string you want to slice.start: The start index of the string to extract. If negative, it's used as (str.Length - start).end: The end index of the string to extract (exclusive). If negative, it's used as (str.Length - end). If the end index is lower than the start index, start and end are inverted.
Returns
Returns the substring, from the given start index to the given end one.
RemoveDiacritics(string)¶
Remove all diacritic characters (accents, combined letters, emojis, ...), keeping their base character in the output string.
Parameters
str: The string from which you want to remove the diacritic characters.
Returns
Returns the processed string.
RemoveSpecialChars(string, string)¶
Removes all characters that are not letters or digits in the given string.
Parameters
str: The string from which you want to remove the characters.allowedChars: The allowed characters in the output string that won't be removed.
Returns
Returns the processed string.
ToPath(string, bool, char)¶
Converts the given string into a path, by removing forbidden characters and using a single character as directory separator.
Parameters
str: The string to convert.normalize: If enabled, the path is resolved to its full path (in the editor, this also resolvesPackages/...virtual paths to their actual folder).separator: The character to use as directory separator.
Returns
Returns the converted string.
Example
PathUtility.ToPath("Assets\\Foo\\Bar"); // "Assets/Foo/Bar"
PathUtility.ToPath("Assets/Foo/Bar", separator: '\\'); // "Assets\Foo\Bar"
ToAbsolutePath(string)¶
If the given string represents a relative path, it's combined with ProjectPath to make it absolute.
Returns
Returns the absolute path string.
Example
// Assuming the project is at "C:/dev/MyProject":
PathUtility.ToAbsolutePath("Assets/Foo"); // "C:/dev/MyProject/Assets/Foo"
PathUtility.ToAbsolutePath(""); // the project path
ToRelativePath(string, bool)¶
If the given string represents an absolute path leading to this project, this function makes it relative to ProjectPath.
Returns
Returns the relative path string.
Example
// Assuming the project is at "C:/dev/MyProject":
PathUtility.ToRelativePath("C:/dev/MyProject/Assets/Foo"); // "Assets/Foo"
PathUtility.ToRelativePath("Assets/Foo"); // "Assets/Foo" (already relative)
IsProjectPath(string)¶
Checks if the given path leads to this project.
Returns
Returns true if the given path leads to this project.
Example
PathUtility.IsProjectPath("Assets/Foo"); // true (relative paths are project paths)
PathUtility.IsProjectPath("C:/dev/MyProject/Assets/Foo"); // true
PathUtility.IsProjectPath("C:/Windows/System32"); // false
ToGUIContent(string, Texture2D, string)¶
Converts this string into a GUIContent instance.
Parameters
text: The text of theGUIContent.icon: The icon of theGUIContent.tooltip: The tooltip of theGUIContent.
Returns
Returns the converted GUIContent.
ToGUIContent(string, Texture2D)¶
Converts this string into a GUIContent instance.
Parameters
text: The text of theGUIContent.icon: The icon of theGUIContent.
Returns
Returns the converted GUIContent.
ToGUIContent(string, string)¶
Converts this string into a GUIContent instance.
Parameters
text: The text of theGUIContent.tooltip: The tooltip of theGUIContent.
Returns
Returns the converted GUIContent.
ToGUIContent(Texture2D, string)¶
Converts this string into a GUIContent instance.
Parameters
icon: The icon of theGUIContent.tooltip: The tooltip of theGUIContent.
Returns
Returns the converted GUIContent.
ToGUIContent(string)¶
Converts this string into a GUIContent instance.
Parameters
text: The text of theGUIContent.
Returns
Returns the converted GUIContent.