String operations
Collection of Ikarus functions to manipulate and format strings.
Initialization
The best way to initialize all Ikarus functions is to call MEM_InitAll()
in the Init_Global()
initialization function.
Warning
If you want to use Ikarus in Gothic 1, it is best to define your own Init_Global()
function and call it from every world initialization function.
Implementation
Functions
STR_GetCharAt
STR_GetCharAt
Returns the ASCII value of a character at a specific position in a string.
var string str
The input stringvar int pos
The position of the character
Return value
The function returns the ASCII value of the character at the specified position.
STR_Len
STR_Len
Returns the length of a string.
var string str
The input string
Return value
The function returns the length of the string in characters.
STR_toChar
STR_toChar
Converts a string to a pointer to its character array.
var string str
The input string
Return value
The function returns a pointer to the character array representing the input string str
STR_FromChar
STR_FromChar
Converts a character array to a string.
var int char
Pointer to the character array
Return value
The function returns a string representation of the character array.
STR_SubStr
STR_SubStr
Extracts a substring from a given string.
var string str
The input stringvar int start
The starting position of the substringvar int count
The length of the substring
Return value
The function returns a substring, if the starting position is invalid an empty string is returned.
STR_Prefix
STR_Prefix
Extracts a prefix of a given string, similar to STR_SubStr
, but with the starting position set to the first character of the string.
var string str
The input stringvar int count
The length of the prefix
Return value
The function returns a prefix of the input string with the specified length.
STR_Compare
STR_Compare
Compares two strings lexicographically and returns a result indicating their relative order.
var string str1
The first string to comparevar string str2
The second string to compare
Return Value
The function returns an integer value representing the result of the comparison:
STR_GREATER
(1): Ifstr1
comes lexicographically afterstr2
.STR_EQUAL
(0): Ifstr1
is lexicographically equal tostr2
.STR_SMALLER
(-1): Ifstr1
comes lexicographically beforestr2
.
Examples
The comparison is based on lexicographic order, which is the order of characters as they appear in the ASCII table. Uppercase letters come before lowercase letters.
STR_ToInt
STR_ToInt
Converts a string to an integer.
var string str
The input string
Return Value
The function returns an integer value of the string, if a string is invalid (doesn't contain an integer) zero is returned.
STR_IndexOf
STR_IndexOf
Searches for a substring tok
within a given string and returns the index of the first occurrence of tok
, taking into account upper and lower case letters.
var string str
The string in which to search fortok
.var string tok
The substring to search for withinstr
.
Return Value
The function returns the index at which the first occurrence of tok
begins within str
. If tok
is not found in str
, the function returns -1.
Examples
STR_SplitCount
STR_SplitCount
Counts the number of parts a string splits into when using a specified separator.
var string str
The input string to be split.var string separator
The separator character or string used to split the input string.
Return Value
The function returns a number of parts the input string splits into when using the specified separator.
STR_Split
STR_Split
Splits a string into multiple substrings based on a specified separator and returns the substring at a specified offset.
Parameters
var string str
The input string to be split.var string separator
The separator character or string used to split the input string.var int offset
The index of the substring to be returned after splitting. The index is zero-based.
Return Value
The function returns a substring at the specified offset after splitting the input string. If the offset is greater than or equal to the number of parts generated by splitting, an empty string is returned.
Example
tok1
contains "This", tok2
contains "is", tok3
contains "a", and tok4
contains "sentence.". STR_Upper
STR_Upper
Converts a string to uppercase.
var string str
The input string
Return Value
The function returns a copy of str
with all uppercase letters converted to their corresponding uppercase letters.
STR_Lower
STR_Lower
Converts a string to lowercase.
var string str
The input string
Return Value
The function returns a copy of str
with all lowercase letters converted to their corresponding uppercase letters.