AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [INC] String Stocks (https://forums.alliedmods.net/showthread.php?t=163205)

Exolent[jNr] 07-27-2011 20:30

[INC] String Stocks
 
1 Attachment(s)
String Stocks
Version 0.0.6
by Exolent


Intro:
Ever needed some kind of fancy manipulation for a string that wasn't already available?
With these stocks, you will be able to do almost anything you could want with strings!

Functions:
Code:

is_str_empty(const string[])
is_str_num(const string[])
is_str_alpha(const string[])
is_str_alnum(const string[])
is_str_spaces(const string[])
is_char(c)
is_char_upper(c)
is_char_lower(c)
strrfind(const string[], const sub[], ignorecase = 0, pos = 0)
str_substr(const string[], start, output[], output_len, len = 0)
str_explode(const string[], delimiter, output[][], output_size, output_len)
str_explode_str(const string[], const delimiter[], const output[], output_size, output_len)
str_implode(const input[][], size, delimiter, output[], output_len)
str_implode_str(const input[][], size, const delimiter[], output[], output_len)
str_insert(const string[], const input[], pos, output[], output_len)
str_cat(output[], output_len, ...)
str_parsetok(const text[], token = ' ', trimSpaces = 0, ...)
str_delete(string[], chars, pos)
str_replace(string[], string_len, const what[], const with[], max_replace = 0, ignorecase = 0)
is_str_type(const string[], StrType:flags, const exceptions[] = "")
is_str_float(const string[])
add_commas({Float,_}:value, output[], output_len, bool:is_float = false)
str_addcommas(const string[], output[], output_len)
str_ltrim(string[], const trim[] = " ^n^t^r", ignorecase = 0)
str_rtrim(string[], const trim[] = " ^n^t^r", ignorecase = 0)
str_trim(string[], const trim[] = " ^n^t^r", ignorecase = 0)
str_pad(const string[], pad_size, output[], output_len, const pad_string[] = " ", StrPad:pad_flags = (STRPAD_LEFT | STRPAD_RIGHT))
str_lpad(const string[], pad_size, output[], output_len, const pad_string[] = " ")
str_rpad(const string[], pad_size, output[], output_len, const pad_string[] = " ")
str_repeat(const string[], times, output[], output_len)
str_shuffle(string[])
str_substr_count(const string[], const find[], start = 0, len = 0)
str_ucwords(string[])
str_wordwrap(const string[], output[], output_len, width = 75, const wrapper[] = "^n", bool:cut = false)
str_empty(string[], length = 0)
str_uriencode(const string[], output[], output_len)
str_uridecode(const string[], output[], output_len)
is_str_upper(const string[])
is_str_lower(const string[])
regex_escape(const string[], output[], output_len)
parse_color(const color[], &r = 0, &g = 0, &b = 0)
html_encode(const string[], output[], output_len)
html_decode(const string[], output[], output_len)

Documentation:
See string_stocks.inc.
The forum likes to replace tab characters with 4 spaces, and it just makes it look ugly on here.

Changelog:
Version 0.0.6
- Added html_encode() and html_decode().

Version 0.0.5
- Added parse_color().

Version 0.0.4
- Fixed infinite loop in str_substr_count().

Version 0.0.3
- Several code fixes
- Added str_implode_str() to documentation (it was missing in comments and in post but function existed)
- Added trim[] and ignorecase parameters for str_ltrim() and str_rtrim().
- Added str_trim() function.

Version 0.0.2
- Added is_char(), is_char_upper(), is_char_lower(), str_uriencode(), str_uridecode(), is_str_upper(), is_str_lower(), regex_escape().

Version 0.0.1
- Initial release

Have any problems? Want a new function added?
Speak up! I'll try to help as much as I can and am willing to add new string features as long as they're relevant (meaning I'm not adding a function which copies "hi" into a string).

Destro- 07-27-2011 22:25

Re: [INC] String Stocks
 
Very useful (y).

Thanks :).

pd:add str_to_url(?

@EDIT
other stock
PHP Code:

new szInput "10 5 9 1"
new output[4]
 
function(
szInputoutput)
 
// output[0] = 10
// output[1] = 5
// output[2] = 9
// output[3] = 1 


nikhilgupta345 07-27-2011 22:45

Re: [INC] String Stocks
 
Good job. It'll probably be useful to a lot of people, but sadly, I don't know what I would use these for :(

fysiks 07-27-2011 23:10

Re: [INC] String Stocks
 
@Destro: Your example has nothing to do with URLs.

Quote:

Originally Posted by nikhilgupta345 (Post 1520069)
Good job. It'll probably be useful to a lot of people, but sadly, I don't know what I would use these for :(

You'll know when you need them :).

Destro- 07-27-2011 23:16

Re: [INC] String Stocks
 
Quote:

Originally Posted by fysiks (Post 1520078)
@Destro: Your example has nothing to do with URLs.



You'll know when you need them :).

already know, is another new stock :).

I have to do an English course :S

Hunter-Digital 07-28-2011 10:36

Re: [INC] String Stocks
 
Quote:

Originally Posted by Destro- (Post 1520060)
other stock
PHP Code:

new szInput "10 5 9 1"
new output[4]
 
function(
szInputoutput)
 
// output[0] = 10
// output[1] = 5
// output[2] = 9
// output[3] = 1 


That should be achievable using str_explode()

Exolent[jNr] 08-01-2011 02:25

Re: [INC] String Stocks
 
Updated to Version 0.0.2
Quote:

Originally Posted by Exolent[jNr] (Post 1520006)
Changelog:
Version 0.0.2
- Added is_char(), is_char_upper(), is_char_lower(), str_uriencode(), str_uridecode(), is_str_upper(), is_str_lower(), regex_escape().


drekes 08-01-2011 04:58

Re: [INC] String Stocks
 
I'm sure some of these will come in handy when parsing files in the future.

Good job

nikhilgupta345 08-22-2011 21:48

Re: [INC] String Stocks
 
Got this idea from here.

str_charcount( szString[ ], character )


Returns the amount of times the character is present in a certain string.

Exolent[jNr] 08-22-2011 21:50

Re: [INC] String Stocks
 
str_substr_count() is for that.


All times are GMT -4. The time now is 07:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.