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. React(JSX语法)----JSX拼写

    注意:For DOM differences,such as the inline style attribute,check here. // bad: it displays "FIrs ...

  2. 【学习笔记】oracle 比较运算符,逻辑运算符,特殊运算符,判断空值,大小写敏感

    比较运算符:> 大于,< 小于 >= 大于等于,<= 小于等于 = 等于,!=,<>,^= 不等于 逻辑运算符运算的优先顺序:NOT > AND > O ...

  3. mysql配置命令 CHARACTER_SET_%字符集设置

    参照: http://blog.csdn.net/mzlqh/article/details/7621307点击打开链接 其实现在的ubuntu12. 直接sudo apt-get install M ...

  4. Docker搭建Java Web运行环境

    1. 前提条件 安装了Docker的64位Linux 操作系统 Linux操作系统镜像 Linux版本的JDK压缩包 Linux版本的Tomcat压缩包 2. 启动容器 容器是在镜像的基础上来运行的, ...

  5. C/C++文字常量与常变量的概念与区别 分类: C/C++ 2015-06-10 22:56 111人阅读 评论(0) 收藏

    以下代码使用平台是Windows 64bits+VS2012. 在C/C++编程时,经常遇到以下几个概念:常量.文字常量.符号常量.字面常量.常变量.字符串常量和字符常量,网上博客资料也是千篇千律,不 ...

  6. unity行为树制作AI简单例子(1)

    用行为树来制作AI是非常方便的,今天就给大家简单介绍一下行为树的强大之处. 所用插件 Behavior Designer v1.421 最开始 我使用过Rain插件,不过用过Behavior Desi ...

  7. WEKA运行LIBSVM出现problem evaluating classifier:rand

    原来这个实验已经做了的.也出现了些问题,但是上网找到了解决方法,那个时候是完成数据挖掘的课程论文,用WEKA运行LIBSVM,也没有很深入,简单跑出结果就算了. 这次想着研讨会就讲这个,想着深入进去, ...

  8. 有关vue的总结

    1:使用v-for进行循环渲染: <div v-for="(value, key, index) in object"> {{ index }}. {{ key }} ...

  9. awk 的使用

    awk [-F field-separator] 'commands' input-file(s) 其中,commands 是真正awk命令,[-F域分隔符]是可选的.input-file(s) 是待 ...

  10. Java 使用线程方式Thread和Runnable,以及Thread与Runnable的区别

    一. java中实现线程的方式有Thread和Runnable Thread: public class Thread1 extends Thread{ @Override public void r ...