首页 技术 正文
技术 2022年11月11日
0 收藏 594 点赞 3,368 浏览 2603 个字

String.charAt()/String.charCodeAt()###

string.charAt(n); n:The index of the character that should be returned from string.

  var a = 'abc';
a.charAt(2); //=> 'c'
a.charCodeAt(2); //=>99

String.concat()###

string.concat(value, ...)

  var a = 'abc';
a.concat('def'); //=> 'abcdef'

String.fromCharCode()###

String.fromCharCode(c1, c2, ...); c1, c2, … Zero or more integers that specify the Unicode encodings of the characters in the string to be created.

// Create the string "hello"
var s = String.fromCharCode(104, 101, 108, 108, 111);

String.indexOf() /String.lastIndexOf()###

string.indexOf(substring) ; string.indexOf(substring, start)

 var a = 'abcabc';
a.indexOf('b'); //=> 1
a.indexOf('b', 1); //=> 1
a.indexOf('b', 2); //=> 4

String.match()###

string.match(regexp)

"1 plus 2 equals 3".match(/\d+/g) // Returns ["1", "2", "3"]var url = /(\w+):\/\/([\w.]+)\/(\S*)/;
var text = "Visit my home page at http://www.isp.com/~david";
var result = text.match(url);
if (result != null) {
var fullurl = result[0]; // Contains "http://www.isp.com/~david"
var protocol = result[1]; // Contains "http"
var host = result[2]; // Contains "www.isp.com"
var path = result[3]; // Contains "~david"
}

String.replace()###

string.replace(regexp, replacement)

To ensure that the capitalization of the word “JavaScript” is correct:
text.replace(/javascript/i, "JavaScript");To convert a single name from “Doe, John” format to “John Doe” format:
name.replace(/(\w+)\s*,\s*(\w+)/, "$2 $1");To replace all double quotes with double back and forward single quotes:
text.replace(/"([^"]*)"/g, "''$1''");To capitalize the first letter of all words in a string:
text.replace(/\b\w+\b/g, function(word) {
return word.substring(0,1).toUpperCase() +
word.substring(1);
});

String.search()###

**string.search(regexp)###

var s = "JavaScript is fun";
s.search(/script/i) // Returns 4
s.search(/a(.)a/) // Returns 1

String.slice()###

string.slice(start, end)

var s = "abcdefg";
s.slice(0,4) // Returns "abcd"
s.slice(2,4) // Returns "cd"
s.slice(4) // Returns "efg"
s.slice(3,-1) // Returns "def"
s.slice(3,-2) // Returns "de"
s.slice(-3,-1) // Should return "ef"; returns "abcdef" in IE 4

String.split()###

string.split(delimiter, limit)

"1:2:3:4:5".split(":"); // Returns ["1","2","3","4","5"]
"|a|b|c|".split("|"); // Returns ["", "a", "b", "c", ""]var words = sentence.split(/\s+/);"hello".split(""); // Returns ["h","e","l","l","o"]
"hello".split("", 3); // Returns ["h","e","l"]var text = "hello <b>world</b>";
text.split(/(<[^>]*>)/); // Returns ["hello ","<b>","world","</b>",""]

String.substr()

string.substr(start, length)

var s = "abcdefg";
s.substr(2,2); // Returns "cd"
s.substr(3); // Returns "defg"
s.substr(-3,2); // Should return "ef"; returns "ab" in IE 4

String.substring()###

string.substring(from, to)

  var a = 'abcabc';
a.substring(1,3); //=> bc

String.toLowerCase()/String.toLocaleLowerCase()/String.toUpperCase()/String.toLocaleUpperCase()#

String.trim()

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862