Bunoon: TESS | Manual | String

This area contains a set of functions that are used for handling and manipulating javascript Strings. Everything you could want when handling strings is available in this extensive library, allowing you compress and decompress strings (useful for AJAX commands, when dealing with multiple server/client sides), replace sections of strings, format a string using %s and %d sections (for String and Number), and much much more.

As a bonus, some functions available extend existing functionality available in Javascript without overriding the original implementation (for example, Merge).

Takes a string and converts the first letter to uppercase.

The main arguments for this function are as follows:

  • sString [String] - The string that should be adjusted.

The return value for this function is as follows:

  • [Object] - An object or string containing the new string (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.UpFirstLetter('string test');

Takes a property name (CSS style) and converts it into the style required for "currentStyle".

The main arguments for this function are as follows:

  • sCSSProperty [String] - The css property name that should be adjusted.

The return value for this function is as follows:

  • [Object] - An object or string containing the new property name (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.GetCurrentStylePropertyName('background-image');

Takes a string and encodes it so it's compatible with web-servers for AJAX URL's.

The main arguments for this function are as follows:

  • sString [String] - The string that should be encoded.

The return value for this function is as follows:

  • [Object] - An object or string containing the encoded string (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Encode('this is a test string');

Takes a URL string and encodes it's values so it's compatible with web-servers.

The main arguments for this function are as follows:

  • sString [String] - The string that should be encoded.

The return value for this function is as follows:

  • [Object] - An object or string containing the encoded URL (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.EncodeURL('?name=John&last=Doe&age=30');

Takes a string and replaces the formatted sections with the items in the arguments list (see arguments for details).

The main arguments for this function are as follows:

  • sString [String] - The string that should be formatted.
  • [arguments] - An arguments object array containing the list of replacement strings (in the correct order).

The return value for this function is as follows:

  • [Object] - An object or string containing the formatted string (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Format('FirstName=%s, LastName=%s, Age=%d', 'John', 'Doe', 30);

Takes a number and pads the left side out with a desired character by the right length.

The main arguments for this function are as follows:

  • nNumber [Number] - The number that should be padded.
  • nLength [Number] - The length the number should be after padding.
  • sCharacter [String] - The character we should pad the number with.

The return value for this function is as follows:

  • [Object] - A string containing the padded number (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.PadNumber(12, 6, '0');

Takes a string and replaces specific areas with the desired replacements.

The main arguments for this function are as follows:

  • sString [String] - The string that should be used.
  • sTarget [String] - The string we are to replace.
  • sReplacement [String] - The string we are to replace the target with.

The return value for this function is as follows:

  • [Object] - The original string with the replacements (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.ReplaceAll('This somenumber is somenumber', 'somenumber', '1');

Takes a string and works out if we should apply a string at the end if it is too long.

The main arguments for this function are as follows:

  • sString [String] - The string that should be used.
  • nLength [Number] - The valid length the string should be before adding the end string.
  • sEndString [String] - The string to add to the end of the main string (... by default).

The return value for this function is as follows:

  • [Object] - The string with the ellipses (if required) at the end (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Truncate('This is an example', 10);

Takes a string and strips out all the HTML elements inside.

The main arguments for this function are as follows:

  • sString [String] - The string that should be stripped.

The return value for this function is as follows:

  • [Object] - The string without the HTML tags in it (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.StripHTML('<div>something</div>');

Takes a string and repeats it a specific amount of times.

The main arguments for this function are as follows:

  • sString [String] - The string that should be repeated.
  • nCount [Number] - The number of times the string should be repeated.

The return value for this function is as follows:

  • [Object] - The string once it's repeated (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Repeat('a', 10);

Takes a string and determines if another string specified is at the start of it or not.

The main arguments for this function are as follows:

  • sString [String] - The string that should be searched.
  • sSearch [String] - The string that we should search for.
  • bCaseSensitive [Boolean] - States if the search should be case sensitive or not (set to true as default).

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state if we have found the string.

Below is an example of how to use this function:

var bDoesStartWith = $T.String.StartsWith('abcdefg', 'abcd');

Takes a string and determines if another string specified is at the end of it or not.

The main arguments for this function are as follows:

  • sString [String] - The string that should be searched.
  • sSearch [String] - The string that we should search for.
  • bCaseSensitive [Boolean] - States if the search should be case sensitive or not (set to true as default).

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state if we have found the string.

Below is an example of how to use this function:

var bDoesEndWith = $T.String.EndsWith('abcdefg', 'abcd');

Takes a string and reverses it.

The main arguments for this function are as follows:

  • sString [String] - The string that should be reversed.

The return value for this function is as follows:

  • [Object] - The string once it's reversed (or null if any error has occurred).

Below is an example of how to use this function:

var bReversed = $T.String.Reverse('this is an example of a string to reverse');

Takes a list of strings and merges them together into a single string (using the delimiter specified beforehand).

The main arguments for this function are as follows:

  • sDelimiter [String] - The string that should be used as the delimiter.
  • [arguments] - An arguments object array containing the list of strings to join.

The return value for this function is as follows:

  • [Object] - The string once it's joined (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Merge(' ', 'this', 'is', 'an', 'example', 'of', 'items', 'to', 'join');

Takes a string and trims the white space off the left/right (and additional tabs if specified).

The main arguments for this function are as follows:

  • sString [String] - The string that should be trimmed.
  • bIncludeTabs [Boolean] - States if tabs should be trimmed as well (set to false as default).

The return value for this function is as follows:

  • [Object] - The string once it's trimmed (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Trim(' Left/Right ');

Takes a string and trims the white space off the left (and additional tabs if specified).

The main arguments for this function are as follows:

  • sString [String] - The string that should be trimmed.
  • bIncludeTabs [Boolean] - States if tabs should be trimmed as well (set to false as default).

The return value for this function is as follows:

  • [Object] - The string once it's trimmed (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.TrimLeft(' Left');

Takes a string and trims the white space off the right (and additional tabs if specified).

The main arguments for this function are as follows:

  • sString [String] - The string that should be trimmed.
  • bIncludeTabs [Boolean] - States if tabs should be trimmed as well (set to false as default).

The return value for this function is as follows:

  • [Object] - The string once it's trimmed (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.TrimRight('Right ');

Searches a string for a specific item and returns a list of all the starting indexes of each item.

The main arguments for this function are as follows:

  • sString [String] - The string that should be searched.
  • sSearch [String] - The string that we should search for.
  • bCaseSensitive [Boolean] - States if the search should be case sensitive or not (set to true as default).

The return value for this function is as follows:

  • [Object] - An array of indexes of each item found (or null if any error has occurred).

Below is an example of how to use this function:

var aIndexes = $T.String.Search('this is another example of a long string and is good testing', 'is');

Takes a string and determines if it is empty or not.

The main arguments for this function are as follows:

  • sString [String] - The string that should be checked.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false.

Below is an example of how to use this function:

var sNewString = $T.String.IsEmpty(' ');

Takes a string and extracts all the letters.

The main arguments for this function are as follows:

  • sString [String] - The string that should be used.

The return value for this function is as follows:

  • [Object] - The string with the extracted characters removed (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.GetLetters('1234abcd5678efgh1234ABCD5678EFGH');

Takes a string and extracts all the numbers.

The main arguments for this function are as follows:

  • sString [String] - The string that should be used.

The return value for this function is as follows:

  • [Object] - The string with the extracted characters removed (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.GetNumbers('1234abcd5678efgh1234ABCD5678EFGH1.2');

Takes a string and extracts all the letters and numbers.

The main arguments for this function are as follows:

  • sString [String] - The string that should be used.

The return value for this function is as follows:

  • [Object] - The string with the extracted characters removed (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.GetLettersNumbers('1234£$%abcd5678efgh1234^&*ABCD5678EFGH1.2');

Takes a string and extracts all the non-numeric characters.

The main arguments for this function are as follows:

  • sString [String] - The string that should be used.

The return value for this function is as follows:

  • [Object] - The string with the extracted characters removed (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.GetNonNumericCharacters('1234£$%abcd5678efgh1234^&*ABCD5678EFGH1.2');

Takes a string and strips a specific length of characters off the left.

The main arguments for this function are as follows:

  • sString [String] - The string that should be stripped.
  • nLength [Number] - The length of characters that should be stripped.

The return value for this function is as follows:

  • [Object] - The string that has been stripped (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.StripLeft('John Doe', 5);

Takes a string and strips a specific length of characters off the right.

The main arguments for this function are as follows:

  • sString [String] - The string that should be stripped.
  • nLength [Number] - The length of characters that should be stripped.

The return value for this function is as follows:

  • [Object] - The string that has been stripped (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.StripRight('John Doe', 4);

Takes a string and removes a list of specific strings (from 'arguments') from it (either just once or all).

The main arguments for this function are as follows:

  • sString [String] - The string that should be used.
  • bRemoveAll [Boolean] - States if we should remove all entries found (set to off by default).
  • [arguments] - An arguments object array containing the list of strings to remove.

The return value for this function is as follows:

  • [Object] - The string that is left after the remove (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Remove('John Doe 30 John Doe 30 John Doe 30', true, 'Doe', '30');

Takes a string and removes a specific character from it (by a certain length) and leaves the same character by a custom length.

The main arguments for this function are as follows:

  • sString [String] - The string that should be used.
  • sChar [String] - The character that should be removed.
  • nLength [Number] - The number of characters (in same sequence) that should be removed.
  • nRemainLength [Number] - The number of characters that should be left after the remove it done.

The return value for this function is as follows:

  • [Object] - The string that is left after the remove (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.RemoveChar('This is a sentence that contained a double space', ' ');

Takes a string and compresses it down so it's smaller in size (if additional checks pass).

The main arguments for this function are as follows:

  • sString [String] - The string that should be compressed.

The return value for this function is as follows:

  • [Object] - The compressed string (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Compress('Enter a really long string here');

Takes a string and decompresses it back to it's original length and value.

The main arguments for this function are as follows:

  • sString [String] - The string that should be decompressed.

The return value for this function is as follows:

  • [Object] - The decompressed string (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Decompress('Enter the compressed string here.')

Takes a string and splits it up into an array by a custom chunk size.

The main arguments for this function are as follows:

  • sString [String] - The string that should be split.
  • nChunkLength [Number] - The length that each chunk should be.
  • bBackwards [Boolean] - States if we should split from right to left of the string.

The return value for this function is as follows:

  • [Object] - The array containing the chunks (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.Chunks('This is a long string to split into chunks.', 5);

Takes a number and converts it into a human readable string (using custom delimiter and block size).

The main arguments for this function are as follows:

  • sString [String] - The number that should be converted.
  • nBlockSize [Number] - The size that each part of the string should be (default is 3).
  • sDelimiter [String] - The delimiter that should be used to split up the new value (default is ,).

The return value for this function is as follows:

  • [Object] - The converted value (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.ReadableNumber(12345678, 3, ',');

Takes a form and builds up a URL string based off the field elements (allowing string encoding, ID use and additional URL starting).

The main arguments for this function are as follows:

  • oForm [Object] - The form that should be used for the URL.
  • sURL [String] - The starting URL that should be used (defaults to the start of "?").
  • bEncodeValues [Boolean] - States if the values for each url entry should be encoded or not (set to false as default).
  • bUseIDs [Boolean] - States if we should use the IDs from each field element (so that the URL can be built correctly, false as default).

The return value for this function is as follows:

  • [Object] - The URL string that has been built up (or null if any error has occurred).

Below is an example of how to use this function:

var sNewString = $T.String.GetFormURL(document.TestForm, '?', false, false);