博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(转)jQuery String Functions
阅读量:6481 次
发布时间:2019-06-23

本文共 5184 字,大约阅读时间需要 17 分钟。

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 , , and 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 ""
    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
Feel free to contact me for any help related to jQuery, I will gladly help you.
 

转载地址:http://hdfuo.baihongyu.com/

你可能感兴趣的文章
[LeetCode] Minimum Depth of Binary Tree
查看>>
,net运行框架
查看>>
Java 中 Emoji 的正则表达式
查看>>
Mixin Network第一届开发者大赛作品介绍- dodice, diceos和Fox.one luckycoin
查看>>
安卓Glide(4.7.1)使用笔记 01 - 引入项目
查看>>
中金易云:为出版社找到下一本《解忧杂货店》
查看>>
Flex布局
查看>>
Material Design之 AppbarLayout 开发实践总结
查看>>
Flutter之MaterialApp使用详解
查看>>
DataBinding最全使用说明
查看>>
原生Js交互之DSBridge
查看>>
Matlab编程之——卷积神经网络CNN代码解析
查看>>
三篇文章了解 TiDB 技术内幕 —— 说计算
查看>>
copy strong weak assign的区别
查看>>
OpenCV 入门
查看>>
css 3D transform变换
查看>>
ele表格合并行之后的selection选中
查看>>
正则表达式分解剖析(一文悟透正则表达式)
查看>>
解决UILable标点符号居中的问题
查看>>
HTML5新特性教程
查看>>