5 #if defined _string_included
8 #define _string_included
12 * Unless otherwise noted, all string functions which take in a writable buffer and maximum length
13 * should have the null terminator INCLUDED in the length. This means that this is valid:
14 * StrCopy(string, sizeof(string), ...)
18 * Calculates the length of a string.
20 * @param str String to check.
21 * @return Length of string, in cells (NOT characters).
23 native strlen(const String:str[]);
26 * Tests whether a string is found inside another string.
28 * @param str String to search in.
29 * @param substr Substring to find inside the original string.
30 * @param caseSensitive If true (default), search is case sensitive.
31 * If false, search is case insensitive.
32 * @return -1 on failure (no match found). Any other value
33 * indicates a position in the string where the match starts.
35 native StrContains(const String:str[], const String:substr[], bool:caseSensitive=true);
38 * Compares two strings lexographically.
40 * @param str1 First string (left).
41 * @param str2 Second string (right).
42 * @param caseSensitive If true (default), comparison is case sensitive.
43 * If false, comparison is case insensitive.
44 * @return -1 if str1 < str2
48 native StrCompare(const String:str1[], const String:str2[], bool:caseSensitive=true);
51 * Returns whether two strings are equal.
54 * @param str1 First string (left).
55 * @param str2 Second string (right).
56 * @param caseSensitive If true (default), comparison is case sensitive.
57 * If false, comparison is case insensitive.
58 * @return True if equal, false otherwise.
60 stock bool:StrEqual(const String:str1[], const String:str2[], bool:caseSensitive=true)
62 return (StrCompare(str1, str2, caseSensitive) == 0);
66 * Copies one string to another string.
67 * NOTE: If the destination buffer is too small to hold the source string,
68 * the destination will be truncated.
70 * @param dest Destination string buffer to copy to.
71 * @param destlen Destination buffer length (includes null terminator).
72 * @param source Source string buffer to copy from.
73 * @return Number of cells written.
75 native StrCopy(String:dest[], destLen, const String:source[]);
78 * Converts a string to an integer.
80 * @param str String to convert.
81 * @param nBase Numerical base to use. 10 is default.
82 * @return Integer conversion of string, or 0 on failure.
84 native StringToInt(const String:str[], nBase=10);
87 * Converts an integer to a string.
89 * @param str Buffer to store string in.
90 * @param maxlength Maximum length of string buffer.
91 * @param num Integer to convert.
92 * @return Number of cells written to buffer.
94 native IntToString(String:str[], maxlength, num);
97 * Converts a string to a floating point number.
99 * @param str String to convert to a foat.
100 * @return Floating point result, or 0.0 on error.
102 native Float:StringToFloat(const String:str[]);
105 * Converts a floating point number to a string.
107 * @param str Buffer to store string in.
108 * @param maxlength Maximum length of string buffer.
109 * @param num Floating point number to convert.
110 * @return Number of cells written to buffer.
112 native FloatToString(String:str[], maxlength, Float:num);