[Include] strlib - String functions!
#1

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 - 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.
Examples

sprintf

pawn Код:
SetGameModeText(sprintf("Hello %s. %d %d %d.", "world", 1, 2, 3));

// GameMode text is now: Hello world. 1 2 3.
isequal

pawn Код:
new str1[] = "HELLO", str2[] = "hello";

if (isequal(str1, str2)) // false
if (isequal(str1, str2, .ignorecase = true)) // true
strexplode

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
*/
strimplode

pawn Код:
new output[128];

strimplode(" ~~ ", output, sizeof(output), "I", "like", "jolly", "ranchers");

// output = "I ~~ like ~~ jolly ~~ ranchers"
strreplace

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"
strtrim

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"
strcount

pawn Код:
new string[] = "cow COW cow COW sheep cow", count;

count = strcount(strong, "cow"); // count = 3
count = strcount(strong, "cow", .ignorecase = true); // count = 5
strfrombin

pawn Код:
new data[] = {0x11223344, 0x55667788, 0x99AABBCC, 0xDDEEFF00};
new string[128];

strfrombin(string, data); // string = "112233445566778899AABBCCDDEEFF00"
Reply


Messages In This Thread
strlib - String functions! - by Slice - 25.07.2012, 15:09
Re: strlib - String functions! - by FireCat - 25.07.2012, 15:42
Re: strlib - String functions! - by Glint - 25.07.2012, 15:43
Re: strlib - String functions! - by Kar - 25.07.2012, 15:43
Re: strlib - String functions! - by IstuntmanI - 25.07.2012, 18:24
Re: strlib - String functions! - by Lorenc_ - 27.07.2012, 00:41
Re: strlib - String functions! - by noobre - 28.07.2012, 16:35
Re: strlib - String functions! - by Ronaldo_raul™ - 28.07.2012, 17:07
AW: strlib - String functions! - by FufLa - 28.07.2012, 17:16
Re: strlib - String functions! - by [MM]RoXoR[FS] - 30.07.2012, 13:49
Re: strlib - String functions! - by Slice - 30.07.2012, 13:54
Re: strlib - String functions! - by Ronaldo_raul™ - 31.07.2012, 14:49
Re: strlib - String functions! - by Slice - 31.07.2012, 15:11
Re: strlib - String functions! - by Ronaldo_raul™ - 31.07.2012, 15:42
Re: strlib - String functions! - by Niko_boy - 31.07.2012, 16:45
Re: strlib - String functions! - by [KHK]Khalid - 01.08.2012, 10:59
Re: strlib - String functions! - by Slice - 01.08.2012, 11:06
Re: strlib - String functions! - by Amit_B - 01.08.2012, 21:56
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 09:51
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 10:15
Re: strlib - String functions! - by Slice - 03.08.2012, 10:43
Re: strlib - String functions! - by Ronaldo_raul™ - 03.08.2012, 11:23
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 12:53
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 13:17
Re: strlib - String functions! - by Slice - 03.08.2012, 14:06
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 15:23
Re: strlib - String functions! - by Bakr - 03.08.2012, 15:42
Re: strlib - String functions! - by Slice - 04.08.2012, 11:46
Re: strlib - String functions! - by milanosie - 08.08.2012, 16:55
Re: strlib - String functions! - by Slice - 08.08.2012, 18:27
Re: strlib - String functions! - by ReVo_ - 08.08.2012, 19:05
Re: strlib - String functions! - by Slice - 09.08.2012, 06:42
Re: strlib - String functions! - by ReVo_ - 09.08.2012, 12:16
Re: strlib - String functions! - by Ballu Miaa - 24.08.2012, 05:01
Re: strlib - String functions! - by MicroD - 24.08.2012, 06:23
Re: strlib - String functions! - by Drake1994 - 27.08.2012, 14:10
Re: strlib - String functions! - by Slice - 30.08.2012, 08:10
Re: strlib - String functions! - by florinadrian96 - 29.05.2013, 13:23
Re: strlib - String functions! - by VeNuZ_ - 21.06.2013, 08:13
Re: strlib - String functions! - by Slice - 21.06.2013, 09:58
Re: strlib - String functions! - by QuaTTrO - 30.09.2013, 15:04
Re: strlib - String functions! - by Slice - 30.09.2013, 15:05
Re: strlib - String functions! - by QuaTTrO - 30.09.2013, 15:10
Re: strlib - String functions! - by Slice - 30.09.2013, 18:47
Re: strlib - String functions! - by QuaTTrO - 01.10.2013, 09:51
Re: strlib - String functions! - by Slice - 01.10.2013, 10:09
Re: strlib - String functions! - by QuaTTrO - 01.10.2013, 10:23
Re: strlib - String functions! - by iZN - 01.10.2013, 16:17
Re: strlib - String functions! - by raider19rus - 05.10.2013, 15:01
Re: strlib - String functions! - by Whitetiger - 21.11.2013, 22:39
Re: strlib - String functions! - by Emmet_ - 21.11.2013, 22:47
Re: strlib - String functions! - by Whitetiger - 22.11.2013, 01:56
Re: strlib - String functions! - by JaKe Elite - 05.12.2014, 09:43
Re: strlib - String functions! - by RedFusion - 08.12.2014, 10:52
Re: strlib - String functions! - by RedFusion - 08.12.2014, 20:54
Re: strlib - String functions! - by 123eee123 - 03.07.2015, 12:05
Re: strlib - String functions! - by Cyber123 - 12.07.2015, 18:20
Re: strlib - String functions! - by MerryDeer - 13.11.2016, 21:16
Re: strlib - String functions! - by YamanSetOG - 23.08.2017, 11:59

Forum Jump:


Users browsing this thread: 1 Guest(s)