MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | NAME |
| 2 | strings |
| 3 | |
| 4 | DESCRIPTION |
| 5 | A string is a data type in LPC. |
| 6 | |
| 7 | It consists of several ASCII characters (letters), numbers |
| 8 | and special characters. ASCII characters may contain of |
| 9 | values between -128 and 127 (e.g. 'A' (65) or '5' (53)), but |
| 10 | 0 is not allowed (because strings are 'null terminated', |
| 11 | which means that marks the end of a string). |
| 12 | |
| 13 | Notations for strings: |
| 14 | "abc" + "def" "ghi" + 5 + "jkl" + to_string( ({'m','n'}) ) |
| 15 | == "abcdefghi5jklmn" |
| 16 | |
| 17 | Special characters must be escaped with a leading '\': |
| 18 | \n (new line) |
| 19 | \t (tabulator) |
| 20 | \b (backspace) |
| 21 | ... |
| 22 | |
| 23 | The single characters can be accessed like an array: |
| 24 | string s; |
| 25 | int i,j; |
| 26 | |
| 27 | s="test"; |
| 28 | |
| 29 | s[0] (ASCII Code (value) of the first character) ='t' |
| 30 | s[<1] (last character) ='t' |
| 31 | s[0..0] (string composed of the first char) ="t" |
| 32 | s[1..<2] (string from second to character before last) ="es" |
| 33 | s[2..] (string from third to last character) ="st" |
| 34 | ... |
| 35 | |
| 36 | String manipulations: |
| 37 | s[0]=s[0]-32 ("test" -> "Test") |
| 38 | s[1..<2]="o" ("test" -> "tot") |
| 39 | ... |
| 40 | |
| 41 | FUNCTIONS |
| 42 | int strlen(string str) |
| 43 | int member(string s, int elem) |
| 44 | int strstr (string str, string str2, int pos) |
| 45 | int to_int(string) |
| 46 | mixed *to_array(string) |
| 47 | string to_string(mixed) |
| 48 | string upperstring(string str) |
| 49 | string lowerstring(string str) |
| 50 | string lower_case(string str) |
| 51 | string capitalize(string str) |
| 52 | string break_string(string str, int width, int space, int leave_lfs) |
| 53 | string sprintf(string fmt, ...) |
| 54 | int sscanf(string str, string fmt, mixed var1, mixed var2, ...) |
| 55 | string *new_explode(string str, string del) |
| 56 | string *explode(string str, string del); |
| 57 | string implode(mixed *arr, string del) |
| 58 | string *regexplode (string text, string pattern) |
| 59 | string *regexp(string *list, string pattern) |
| 60 | |
| 61 | SEE ALSO |
| 62 | arrays, integers, mappings, operators, types |
| 63 | |
| 64 | LAST CHANGED |
| 65 | 12. Mar 2004 Gloinson |