jQuery String Functions

In today’s post, I have put together all jQuery String Functions. Well, I should say that these are not “jQuery String Functions“. These are “JavaScript String Functions“. But as jQuery is built on top of Java Script so you can use them with jQuery as well. So I call them “jQuery String Functions“.

  • charAt(n):Returns the character at the specified index in a string. The index starts from 0.
    var str = "JQUERY By Example";
    var n = str.charAt(2)
    
    //Output will be "U"
  • charCodeAt(n):Returns the Unicode of the character at the specified index in a string. The index starts from 0.
    var str = "HELLO WORLD";
    var n = str.charCodeAt(0);
    
    //Output will be "72"
  • concat(string1, string2, .., stringX):The concat() method is used to join two or more strings. This method does not change the existing strings, but returns a new string containing the text of the joined strings.
    var str1 = "jQuery ";
    var str2 = "By Example!";
    var n = str1.concat(str2);
    
    //Output will be "jQuery By Example!"
  • fromCharCode(n1, n2, …, nX):Converts Unicode values into characters. This is a static method of the String object, and the syntax is always String.fromCharCode().
    var n = String.fromCharCode(65);
    //Output will be "A"
  • indexOf(searchvalue, [start]):Returns the position of the first occurrence of a specified value in a string. This method returns -1 if the value to search for never occurs. This method is case sensitive!
    var str="Hello world, welcome to the my blog.";
    var n=str.indexOf("welcome");
    
    //Output will be "13"
  • lastIndexOf(searchvalue, [start]):Returns the position of the last occurrence of a specified value in a string. The string is searched from the end to the beginning, but returns the index starting at the beginning, at postion 0. Returns -1 if the value to search for never occurs. This method is case sensitive!
    var str="Hello planet earth, you are a great planet.";
    var n=str.lastIndexOf("planet");
    
    //Output will be "36"
  • substr(start, [length]):The substr() method extracts parts of a string, beginning at the character at the specified posistion, and returns the specified number of characters.
    var str="Hello world!";
    var n=str.substr(2,3)
    
    //Output will be "llo"
  • substring(from, [to]):The substring() method extracts the characters from a string, between two specified indices, and returns the new sub string. This method extracts the characters in a string between “from” and “to”, not including “to” itself.
    var str="Hello world!";
    var n=str.substring(2,3)
    
    //Output will be "l"
  • toLowerCase():The toLowerCase() method converts a string to lowercase letters.
    var str="HELLO WoRld!";
    str = str.toLowerCase();
    //Output will be "hello world!"
  • toUpperCase():The toUpperCase() method converts a string to uppercase letters.
    var str="hello WoRLd!";
    str = str.toUpperCase();
    //Output will be "HELLO WORLD!"

     

  • match(regexp):The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.
    var str="The rain in SPAIN stays mainly in the plain";
    var n=str.match(/ain/g);
    
    //Output will be "ain,ain,ain"
    //There are 3 matches with the "ain" regex in small letters. So it returns ain 3 times.
  • replace(searchvalue, newvalue):The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.
    var str="Visit jQuery Blog!";
    var n = str.replace("jQuery ","jQuery By Example ");
    
    //Output will be "Visit jQuery By Example Blog!"
  • search(searchvalue):The search() method searches a string for a specified value, or regular expression, and returns the position of the match. This method returns -1 if no match is found.
    var str="Visit jQuery Blog!";
    var n = str.search("jQuery");
    
    //Output will be "6"
  • slice(start, [end]):The slice() method extract parts of a string and returns the extracted parts in a new string. Use the start and end parameters to specify the part of the string you want to extract. The first character has the position 0, the second has position 1, and so on.
    var str="Visit jQuery Blog!";
    var n = str.slice(6,12);
    
    //Output will be "jQuery"

Related Posts


4 thoughts on “jQuery String Functions

  1. kore dizileri izle

    Great one website manager achievement website post fantastic sharings on this blog constantly have fun

    Reply
  2. Shayne

    Nice a single blog proprietor good results blog submit great sharings with this webpage often have pleasurable

    Reply
  3. Cedric Bartlette

    I just want to mention I’m newbie to blogging and definitely liked you’re web-site. More than likely I’m likely to bookmark your website . You surely come with tremendous articles and reviews. Bless you for sharing with us your website page.

    Reply
  4. website jquery

    Wow, awesome blog format! How long have you been blogging for? you made running a blog look easy. The overall glance of your web site is great, let alone the content material!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*