String functions
Functions to manipulate and format strings.
Str_Format
Str_Format
Returns formatted string using format specifiers
Format specifiers:
%s
- inserts a string%i
- inserts an integer number%x
- inserts an integer in hexadecimal%f
- inserts a floating point number%b
- inserts a logical expression%p
- inserts a pointer
return
- formatted string
Examples
Examples
Very powerful function, can be used to streamline strings used in the scripts as well as optimize them for translations.
Define constants containing the string with format specifiers.
Then define two format functions as such:
Tip
Since the whole translatable string is saved in one constant, it is very easy for translators to change the word order. This was not possible to do without code change to the ConcatStrings
function calls within the scripts.
With this simple change, translators have to translate only 2 strings instead of 30 (15 + 15 slots) and only 2 strings are compiled into the compiled Menu.dat
file.
Str_GetLocalizedString
Str_GetLocalizedString
Returns a string in the current language, otherwise in English. Arguments MUST be encoded in UTF-8! The result string will be converted to appropriate ANSI string.
russian
- Russian stringenglish
- English stringgerman
- German stringpolish
- Polish stringreturn
- string in the current language
Str_GetLocalizedStringEx
Str_GetLocalizedStringEx
Returns a string in the current language, otherwise in English. Offers additional languages
russian
- Russian stringenglish
- English stringgerman
- German stringpolish
- Polish stringromanian
- Romanian stringitalian
- Italian stringczech
- Czech stringspanish
- Spanish stringreturn
- string in the current language
Str_UTF8_to_ANSI
Str_UTF8_to_ANSI
Converts UTF-8 string into an ANSI string with codePage
utf8
- string encoded in UTF8codePage
- codePage id, can be obtained from Str_GetCurrentCPreturn
-
Str_GetCurrentCP
Str_GetCurrentCP
Return the code page corresponding to the current language set in the Union System
return
- code page corresponding to the current language
Str_GetLength
Str_GetLength
Returns the length of a string
str
- string to be measuredreturn
- length of the string