Jump to content

Safe string manipulation functions v2

Sign in to follow this  

1 Screenshot

About This File

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>
endswith("hypothermia", "thermia") // true
endswith("hypothermia", "glycemia") // false



capitalize("<string>")
returns <string> with its first letter being capitalized
capitalize("the quick brown fox") // The quick brown fox



titlecase("<string>")
returns <string> with the first letter of every word capitalized
titlecase("the quick brown fox") // The Quick Brown Fox



camelcase("<string>")
returns <string> concatenated in a camelCase fashion
camelcase("the quick brown fox") // theQuickBrownFox



zfill("<string>"{, <width>{, "<padding>"}})
returns <string> padded to the left up to <width> with <padding>
zfill(69, 6, "0"); // 000069
zfill(1337, 6, "0"); // 001337



format_number(<number>{, "<separator>"})
formats a number with <separator>
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
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
reverse("Hello world!") // !dlrow olleH



repeat("<string>", <multiplier>)
repeats <string> <multiplier> times
repeat("Foo", 4) // FooFooFooFoo




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

shuffle("abcdefg") // dgabefc (example, unpredictable)


 


What's New in Version v2   See changelog

Released

  • added reverse()
  • added repeat()
  • added shuffle()



User Feedback

Recommended Comments

There are no comments to display.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.