Strings

Functions


charcode

int charcode(string text)

Returns ASCII code for the first character in given string.


get_string_pointer

sfall.h

int get_string_pointer(string text)

(DEPRECATED) Returns a pointer to a string variable or to a text

  • NOTE: this function is intended for use only in HOOK_DESCRIPTIONOBJ. Starting from sfall 4.4/3.8.40, you can return normal strings directly in the hook without calling the function

string_find

sfall.h

int string_find(string haystack, string needle)

Returns the position of the first occurrence of a needle string in a haystack string, or -1 if not found. The first character position is 0 (zero).


string_find_from

sfall.h

int string_find_from(string haystack, string needle, int pos)

Works the same as string_find, except you can specify the position to start the search.

  • If pos is negative - it indicates a position starting from the end of the string, similar to substr().

string_format

sfall.h

string string_format(string format, any val1, any val2, ...)

Formats given values using standard syntax of C printf function (google “printf” for format details). However, it is limited to formatting up to 7 values.

  • The format string is limited to 1024 characters

string_format_array

lib.strings.h

string string_format_array(string format, int array)

The same as string_format, but accepts an array of parameters.


string_replace

lib.strings.h

string string_replace(string str, string search, string replace)

Replaces all occurances of a given search string in a string with a given replacement string.


string_split

array string_split(string text, split)

Takes a string and a seperator, searches the string for all instances of the seperator, and returns a temp array filled with the pieces of the string split at each instance. If you give an empty string as the seperator, the string is split into individual characters. You can use this to search for a substring in a string like this: strlen(get_array(string_split(haystack, needle), 0))


string_to_case

string sfall_func2("string_to_case", string text, int toCase)

Converts all letters in the given string to the specified case.

toCase: 0 - lowercase, 1 - uppercase

NOTE: this function works only for English letters of A-Z/a-z.


strlen

int strlen(string text)

Returns string length.


substr

string substr(string text, int start, int length)

Cuts a substring from a string starting at “start” up to “length” characters. The first character position is 0 (zero).

  • If start is negative - it indicates a position starting from the end of the string (for example substr("test", -2, 2) will return last 2 charactes: “st”).
  • If length is negative - it means so many characters will be omitted from the end of string (example: substr("test", 0, -2) will return string without last 2 characters: “te”).
  • If length is zero - it will return a string from the starting position to the end of the string. New behavior for sfall 4.2.2/3.8.22