25.07.2012, 15:09
(
Последний раз редактировалось Slice; 11.10.2013 в 11:43.
)
strlib
String functions. This project is hosted on GitHub, and I encourage you to contribute to this include.
Post your own string functions and I'll add them!
Download: At the GitHub page.
Functions
sprintf
isequal
strexplode
strimplode
strreplace
strtrim
strcount
strfrombin
String functions. This project is hosted on GitHub, and I encourage you to contribute to this include.
Post your own string functions and I'll add them!
Download: At the GitHub page.
Functions
- sprintf - Returns a formatted string.
- strgetc - Get a character from a specific index in a string (packed or not packed).
- isempty - Find out if a string is empty.
- isequal - Compare two strings.
- strexplode - Split a string by a given delimiter.
- strimplode - Glue together strings into one.
- strreplace - Replace occurrences of the search string with the replacement string.
- strtrim - Trim whitespace or a specific group of characters from a string.
- strcount - Count substrings.
- strfromliteral - Read a string from a PAWN string literal.
- strtoliteral - Build a PAWN string literal from a given string.
- strfrombin - Convert an array to a string.
- strtobin - Convert a string to an array.
- utf8encode/utf8decode - Encode/decode UTF-8 strings.
sprintf
pawn Код:
SetGameModeText(sprintf("Hello %s. %d %d %d.", "world", 1, 2, 3));
// GameMode text is now: Hello world. 1 2 3.
pawn Код:
new str1[] = "HELLO", str2[] = "hello";
if (isequal(str1, str2)) // false
if (isequal(str1, str2, .ignorecase = true)) // true
pawn Код:
new output[10][10], count;
count = strexplode(output, "I, like, jolly, ranchers", ",");
for (new i = 0; i < count; i++)
print(output[i]);
/* Output:
I
like
jolly
ranchers
*/
pawn Код:
new output[128];
strimplode(" ~~ ", output, sizeof(output), "I", "like", "jolly", "ranchers");
// output = "I ~~ like ~~ jolly ~~ ranchers"
pawn Код:
new string[128] = "Hello world";
strreplace(string, "world", "earth"); // string = "Hello earth"
strreplace(string, "HELLO", "Hola"); // string = "Hello earth" (no match for "HELLO")
strreplace(string, "HELLO", "Hola", .ignorecase = true); // string = "Hola earth"
pawn Код:
new string[128] = " XXbla blaY ";
strtrim(string); // string = "XXbla blaY"
strtrim(string, "XY"); // string = "bla bla"
string = "/Users/home/bla/bla/";
strtrim(string, "/\\", .edges = trim_right); // string = "/Users/home/bla/bla"
pawn Код:
new string[] = "cow COW cow COW sheep cow", count;
count = strcount(strong, "cow"); // count = 3
count = strcount(strong, "cow", .ignorecase = true); // count = 5
pawn Код:
new data[] = {0x11223344, 0x55667788, 0x99AABBCC, 0xDDEEFF00};
new string[128];
strfrombin(string, data); // string = "112233445566778899AABBCCDDEEFF00"