jString.js – Light Javascript String Library

jString-logoJavascript String object comes with “out-of-box” set of methods such as indexOf(), substring() and split() that help in manipulating a string objects. However, some advanced but frequently needed functions are still not part of the standard JS String. jString.js is a light JS library (1 Kb) that gathers into one js file set of methods extending String object with some of the frequently needed functions.

Objective:

  • What methods does jString.js include?

Environment & Tools:

  • Browser (Firefox, Chrome, IE,…)

Library

To use this library, include it under <head> in HTML file as following:

<script src="jstring.js" type="text/javascript" language="javascript"></script>

( 1 ) String.contains()

This method checks if string contains specific character or substring

"normal text".contains("t");
// return true

( 2 ) String.count()

This method counts the occurrence of specific character or substring in string

"normal text".count("t");
// return 2

( 3 ) String.capitalize()

This method capitalize the first character of the string

"normal text".capitalize();
// return "Normal text";

( 4 ) String.clear()

This method remove extra white spaces

" normal   text ".clear();
// return "normal text";

( 5 ) String.endsWith()

This method check if the string ends with specific character of substring

"normal text".endsWith("ext");
// return true

( 6 ) String.insert()

This method will insert a new string or character into a specified location

"normal text".insert("X", 4);
// return "normXal text"

4 thoughts on “jString.js – Light Javascript String Library

Comments are closed.