Safe string manipulation functions

Safe string manipulation functions v2

No permission to download
Content Author
The Mana World
This script provides safe string manipulation functions that do not require PCRE to be enabled at compile time, making your scripts more portable.



startswith("<string>", "<substring>")
returns true if <string> begins with <substring>

startswith("hypothermia", "hypo") // true
startswith("hypothermia", "hyper") // false

endswith("<string>", "<substring>")
returns true if <string> ends with <substring>
Code:
endswith("hypothermia", "thermia") // true
endswith("hypothermia", "glycemia") // false
capitalize("<string>")
returns <string> with its first letter being capitalized
Code:
capitalize("the quick brown fox") // The quick brown fox
titlecase("<string>")
returns <string> with the first letter of every word capitalized
Code:
titlecase("the quick brown fox") // The Quick Brown Fox
camelcase("<string>")
returns <string> concatenated in a camelCase fashion
Code:
camelcase("the quick brown fox") // theQuickBrownFox
zfill("<string>"{, <width>{, "<padding>"}})
returns <string> padded to the left up to <width> with <padding>
Code:
zfill(69, 6, "0"); // 000069
zfill(1337, 6, "0"); // 001337
format_number(<number>{, "<separator>"})
formats a number with <separator>
Code:
format_number(50) // 50
format_number(50000) // 50,000
format_number(5000000) // 5,000,000
strip("<string>")
returns <string> without spaces at the beginning or end
Code:
strip("  the quick brown fox") // "the quick brown fox"
strip("the quick brown fox  ") // "the quick brown fox"
strip(" the quick brown fox ") // "the quick brown fox"
reverse("<string>")
returns <string> reversed
Code:
reverse("Hello world!") // !dlrow olleH
repeat("<string>", <multiplier>)
repeats <string> <multiplier> times
Code:
repeat("Foo", 4) // FooFooFooFoo




shuffle("<string>")
returns <string> shuffled

Code:
shuffle("abcdefg") // dgabefc (example, unpredictable)
Author
meko
Downloads
24
Views
2,273
First release
Last update

Ratings

0.00 star(s) 0 ratings

More resources from meko

  • Randomization helper functions
    Randomization helper functions
    This script provides syntactic sugar for randomization. Works fine with both strings and...
  • Area timer functions
    Area timer functions
    This script provides functions to add (or remove) timers to every player in the area or map.    ...
  • Hash table
    Hash table
    This plugin exposes the internal hash table (strdb) to the script engine to provide a key-value...
  • Array manipulation functions
    Array manipulation functions
    This script provides various array manipulation functions, and more might be added in the...
  • Date and Time functions
    Date and Time functions
    This script provides functions to easily calculate date and time. More functions might be added...

Latest updates

  1. Version v2

    added reverse() added repeat() added shuffle()
Back
Top