Skip to content

Instantly share code, notes, and snippets.

@jaytaph
Last active December 29, 2015 04:48
Show Gist options
  • Save jaytaph/7616908 to your computer and use it in GitHub Desktop.
Save jaytaph/7616908 to your computer and use it in GitHub Desktop.
class string {
public method pad(numerical width, numerical direction = PAD_RIGHT); // PAD_LEFT, PAD_RIGHT, PAD_BOTH
public method utf8(); // shortcut to convert("utf-8");
public method utf16(); // shortcut to convert("utf-16");
public method bytes(); // Return some kind of bytestream?
public method convert(string charset); // Convert to different charset
public method byte_length(); // Returns number of BYTES in this string (which can be more than actual characters)
public method char_length(); // shortcut to length();
public method isNumerical(); // Contains numerical value
public method isHex(); // Contains hexadecimal value ([0-9A-F]+)
public method isAlpha(); // Contains A-Z chars
public method isAlphaNum(); // Contains A-Z 0-9 chars
public method isLower(); // Only lowercase chars?
public method isSpace(); // Only space chars (\t\n \r etc)
public method isUpper(); // Only uppercase chars?
public method lower(); // Convert to lower case
public method upper(); // Convert to upper case
public method capitalize(); // Capitalize string (every word starts with UC and rest LC)
public method replace(string old, string new); // "foobar".replace("bar", "test"); -> footest
public method replace(string old, string new, numerical count); // "foobarbar".replace("bar", "test", 1); -> footestbar
public method split(string old, numerical max); // Split string into list of strings
public method trim(string charlist, directory = TRIM_RIGHT); // TRIM_LEFT, TRIM_RIGHT, TRIM_BOTH
public method startsWith(string prefix); // boolean when string starts with prefix
public method endsWith(string postfix); // boolean when string ends with prefix
public method match(Regex re); // true when this string matches the regex
public method format(); // sprintf()
public method substring(); // splice() shortcut
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment