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 JavaScript so you can use them with jQuery as well. So I call them "jQuery String Functions".

Earlier I had posted about jQuery solution to split string, replace string, substring and trim string And In this post, see all jQuery/JavaScript string functions in action with examples.

Related Post:

  • charAt(n): Returns the character at the specified index in a string. The index starts from 0.

    1 var str = "JQUERY By Example";
    2 var n = str.charAt(2)
    3   
    4 //Output will be "U"
  • charCodeAt(n): Returns the Unicode of the character at the specified index in a string. The index starts from 0.
    1 var str = "HELLO WORLD";
    2 var n = str.charCodeAt(0);
    3   
    4 //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.
    1 var str1 = "jQuery ";
    2 var str2 = "By Example!";
    3 var n = str1.concat(str2);
    4   
    5 //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().
    1 var n = String.fromCharCode(65);
    2   
    3 //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!
    1 var str="Hello world, welcome to the my blog.";
    2 var n=str.indexOf("welcome");
    3   
    4 //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!
    1 var str="Hello planet earth, you are a great planet.";
    2 var n=str.lastIndexOf("planet");
    3   
    4 //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.
    1 var str="Hello world!";
    2 var n=str.substr(2,3)
    3   
    4 //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.
    1 var str="Hello world!";
    2 var n=str.substring(2,3)
    3   
    4 //Output will be "l"
  • toLowerCase(): The toLowerCase() method converts a string to lowercase letters.
    1 var str="HELLO WoRld!";
    2 str = str.toLowerCase();
    3 //Output will be "hello world!"
  • toUpperCase(): The toUpperCase() method converts a string to uppercase letters.
    1 var str="hello WoRLd!";
    2 str = str.toUpperCase();
    3 //Output will be "HELLO WORLD!"

    Also read "jQuery Code: Change text to Uppercase"

    Download plugin for Uppercase, lowercase, title case & pascal case
  • match(regexp): The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.
    1 var str="The rain in SPAIN stays mainly in the plain"
    2 var n=str.match(/ain/g);
    3   
    4 //Output will be "ain,ain,ain"
    5 //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.
    1 var str="Visit jQuery Blog!";
    2 var n = str.replace("jQuery ","jQuery By Example ");
    3   
    4 //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.
    1 var str="Visit jQuery Blog!";
    2 var n = str.search("jQuery");
    3   
    4 //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.
    1 var str="Visit jQuery Blog!";
    2 var n = str.slice(6,12);
    3   
    4 //Output will be "jQuery"
  • split(separator, [limit]): Read Split function in jQuery

Feel free to contact me for any help related to jQuery, I will gladly help you.

 
Posted by jQueryByExample
-----------------------------------------------我是华丽的分割线----------------------------------------------------
 

在javascript、Jquery里面好像是没有String.format();这个函数的,所以我们在拼接字符串的时候就特别的辛苦,生怕又打错,而且又乱,所以就自己去写一个函数来代替。

String.format = function() {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    for ( var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
};
// var a = "我喜欢吃{0},也喜欢吃{1},但是最喜欢的还是{0},偶尔再买点{2}";
// alert(String.format(a, "苹果","香蕉","香梨"));
// 结果:我喜欢吃苹果,也喜欢吃香蕉,但是最喜欢的还是苹果,偶尔再买点香梨

是从0位开始的。

建议自己把这些东西写进一个js文件,每次使用就调用可以了

jQuery String Functions的更多相关文章

  1. jquery.string.js

    /** * jquery.string - Prototype string functions for jQuery * version: 1.1.0 * (c) 2008-2011 David E ...

  2. Part 11 string functions in sql server

    Built in string functions in sql server 2008 LEFT, RIGHT, CHARINDEX and SUBSTRING functions in sql s ...

  3. [Training Video - 4] [Groovy] String Functions

    def x="I like to read books before bed" def temp = x.split(" ") log.info "S ...

  4. Mysql String Functions

    SUBSTRING_INDEX(str,delim,count) 按标识符截取指定长度的字符串 mysql); -> 'www.mysql' mysql); -> 'mysql.com' ...

  5. 【python】string functions

    1.str.replace(word0,word1)  ##用word1替换str中所有的word0 >>> 'tea for too'.replace('too', 'two') ...

  6. jquery判空 string类型的日期比较大小

    jquery 判空 if(value.length<=0){  alert("kongzhi"); } jquery string类型的日期比较大小 var startTim ...

  7. [Javascript] String Padding in Javascript using padStart and padEnd functions

    ES2017 added two new string functions. They are padStart and padEndfunctions. In this lesson, we wil ...

  8. 一个jQuery扩展工具包

    带有详尽注释的源代码: var jQuery = jQuery || {}; // TODO // ###################################string操作相关函数### ...

  9. JQuery常用API 核心 效果 JQueryHTML 遍历 Event事件

    JQuery 常用API 参考资料:JQuery 官网   jQuery API 中文文档 核心 jQuery 对象 jQuery() 返回匹配的元素集合,无论是通过在DOM的基础上传递的参数还是创建 ...

随机推荐

  1. Zookeeper概论(对zookeeper的概论、原理、架构等的理解)

    Zookeeper概论(对zookeeper的概论.原理.架构等的理解) 一.概论 Zookeeper是一个分布式的.开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是h ...

  2. tableView优化性能

    在iOS应用中,UITableView应该是使用率最高的视图之一了.iPod.时钟.日历.备忘录.Mail.天气.照片.电话.短信. Safari.App Store.iTunes.Game Cent ...

  3. Python实例1

    1.有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 错解: 正解: 源码: #!/usr/bin/python for i in range(1,5): for j in ...

  4. Java中抽象类和接口

    抽象类: 为什么要用抽象类? 1.父类的方法好多情况下是没有内容的.例如:USB是一个父类,里面的方法的函数体是可以不写,通过子类可以重写. 2.万一子类没有重写正确,是没有没有提示的.例如:父类中函 ...

  5. UITabBarButton 点击失效问题

    开发过程: 在创建一个UIWindow时,直接在window上添加手势动作. 开发代码: UITapGestureRecognizer *tapRecognizer=[[UITapGestureRec ...

  6. SolrCloud分布式集群部署步骤

    Solr及SolrCloud简介 Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口.用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成 ...

  7. kickstart+ftp+tftp+dhcp+PXE

    ##########yum less install.log #看安装log yum install system-config-kickstart* -y yum install tftp* -y ...

  8. mysql学习之触发器

    在借阅表和读者表当中存在着这样的关系,如果在借阅表当中添加一条数据,读者表当中对应的累计借书字段就自增1,如果在借阅表当中删除一条数据,读者表当中对应的累计借书字段就自减1,实现本功能的方法如下. 1 ...

  9. browser shell

    我一直坚信,做项目需要通过文档来总结.一来可以梳理自己的项目和思路,二来可以备忘,三则可以为有同样需求的朋友提供一些参考.如果一直不进行总结,真的很可能是写了多年的代码,却只有一年的经验.当学习一项新 ...

  10. javascript 键盘输入过滤,只能输入数字,小数一位且只能输入5

    $("#right_div2 input[type='text'][class='textClass'][id^='asd_']").live("keydown" ...