ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:21.70KB ,
资源ID:4164295      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4164295.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(js 字符串处理.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

js 字符串处理.docx

1、js 字符串处理js 字符串处理关键字: js Java代码 1. JavaScript字符串函数大全 2. JS自带函数 3. concat 4. 将两个或多个字符的文本组合起来,返回一个新的字符串。 5. vara=hello; 6. varb=,world; 7. varc=a.concat(b); 8. alert(c); 9. /c=hello,world 10. indexOf 11. 返回字符串中一个子串第一处出现的索引(从左到右搜索)。如果没有匹配项,返回-1。 12. varindex1=a.indexOf(l); 13. /index1=2 14. varindex2=a.

2、indexOf(l,3); 15. /index2=3 16. charAt 17. 返回指定位置的字符。 18. varget_char=a.charAt(0); 19. /get_char=h 20. lastIndexOf 21. 返回字符串中一个子串最后一处出现的索引(从右到左搜索),如果没有匹配项,返回-1。 22. varindex1=lastIndexOf(l); 23. /index1=3 24. varindex2=lastIndexOf(l,2) 25. /index2=2 26. match 27. 检查一个字符串匹配一个正则表达式内容,如果么有匹配返回null。 28.

3、 varre=newRegExp(/w+$/); 29. varis_alpha1=a.match(re); 30. /is_alpha1=hello 31. varis_alpha2=b.match(re); 32. /is_alpha2=null 33. substring 34. 返回字符串的一个子串,传入参数是起始位置和结束位置。 35. varsub_string1=a.substring(1); 36. /sub_string1=ello 37. varsub_string2=a.substring(1,4); 38. /sub_string2=ell 39. substr 40.

4、 返回字符串的一个子串,传入参数是起始位置和长度 41. varsub_string1=a.substr(1); 42. /sub_string1=ello 43. varsub_string2=a.substr(1,4); 44. /sub_string2=ello 45. replace 46. 用来查找匹配一个正则表达式的字符串,然后使用新字符串代替匹配的字符串。 47. varresult1=a.replace(re,Hello); 48. /result1=Hello 49. varresult2=b.replace(re,Hello); 50. /result2=,world 51

5、. search 52. 执行一个正则表达式匹配查找。如果查找成功,返回字符串中匹配的索引值。否则返回-1。 53. varindex1=a.search(re); 54. /index1=0 55. varindex2=b.search(re); 56. /index2=-1 57. slice 58. 提取字符串的一部分,并返回一个新字符串(与substring相同)。 59. varsub_string1=a.slice(1); 60. /sub_string1=ello 61. varsub_string2=a.slice(1,4); 62. /sub_string2=ell 63.

6、split 64. 通过将字符串划分成子串,将一个字符串做成一个字符串数组。 65. vararr1=a.split(); 66. /arr1=h,e,l,l,o 67. length 68. 返回字符串的长度,所谓字符串的长度是指其包含的字符的个数。 69. varlen=a.length(); 70. /len=5 71. toLowerCase 72. 将整个字符串转成小写字母。 73. varlower_string=a.toLowerCase(); 74. /lower_string=hello 75. toUpperCase 76. 将整个字符串转成大写字母。 77. varupp

7、er_string=a.toUpperCase(); 78. /upper_string=HELLO 79. 80. /* 81. * 82. 字符串函数扩充 83. * 84. */85. 86. /* 87. = 88. /去除左边的空格 89. = 90. 91. */92. String.prototype.LTrim=function() 93. 94. returnthis.replace(/(s*)/g,); 95. 96. 97. 98. /* 99. = 100. /去除右边的空格 101. = 102. */103. String.prototype.Rtrim=funct

8、ion() 104. 105. returnthis.replace(/(s*$)/g,); 106. 107. 108. /* 109. = 110. /去除前后空格 111. = 112. */113. String.prototype.Trim=function() 114. 115. returnthis.replace(/(s*)|(s*$)/g,); 116. 117. 118. /* 119. = 120. /得到左边的字符串 121. = 122. */123. String.prototype.Left=function(len) 124. 125. 126. if(isNa

9、N(len)|len=null) 127. 128. len=this.length; 129. 130. else131. 132. if(parseInt(len)this.length) 133. 134. len=this.length; 135. 136. 137. 138. returnthis.substr(0,len); 139. 140. 141. 142. /* 143. = 144. /得到右边的字符串 145. = 146. */147. String.prototype.Right=function(len) 148. 149. 150. if(isNaN(len)|

10、len=null) 151. 152. len=this.length; 153. 154. else155. 156. if(parseInt(len)this.length) 157. 158. len=this.length; 159. 160. 161. 162. returnthis.substring(this.length-len,this.length); 163. 164. 165. 166. /* 167. = 168. /得到中间的字符串,注意从0开始 169. = 170. */171. String.prototype.Mid=function(start,len)

11、172. 173. returnthis.substr(start,len); 174. 175. 176. 177. /* 178. = 179. /在字符串里查找另一字符串:位置从0开始 180. = 181. */182. String.prototype.InStr=function(str) 183. 184. 185. if(str=null) 186. 187. str=; 188. 189. 190. returnthis.indexOf(str); 191. 192. 193. /* 194. = 195. /在字符串里反向查找另一字符串:位置0开始 196. = 197.

12、*/198. String.prototype.InStrRev=function(str) 199. 200. 201. if(str=null) 202. 203. str=; 204. 205. 206. returnthis.lastIndexOf(str); 207. 208. 209. /* 210. = 211. /计算字符串打印长度 212. = 213. */214. String.prototype.LengthW=function() 215. 216. returnthis.replace(/x00-xff/g,*).length; 217. 218. 219. /*

13、220. = 221. /是否是正确的IP地址 222. = 223. */224. String.prototype.isIP=function() 225. 226. 227. varreSpaceCheck=/(d+).(d+).(d+).(d+)$/; 228. 229. if(reSpaceCheck.test(this) 230. 231. this.match(reSpaceCheck); 232. if(RegExp.$1=0233. &RegExp.$2=0234. &RegExp.$3=0235. &RegExp.$4=0) 236. 237. returntrue; 23

14、8. 239. else240. 241. returnfalse; 242. 243. 244. else245. 246. returnfalse; 247. 248. 249. 250. 251. 252. /* 253. = 254. /是否是正确的长日期 255. = 256. */257. String.prototype.isLongDate=function() 258. 259. varr=this.replace(/(s*)|(s*$)/g,).match(/(d1,4)(-|/)(d1,2)2(d1,2)(d1,2):(d1,2):(d1,2)$/); 260. if(r

15、=null) 261. 262. returnfalse; 263. 264. vard=newDate(r1,r3-1,r4,r5,r6,r7); 265. return(d.getFullYear()=r1&(d.getMonth()+1)=r3&d.getDate()=r4&d.getHours()=r5&d.getMinutes()=r6&d.getSeconds()=r7); 266. 267. 268. 269. /* 270. = 271. /是否是正确的短日期 272. = 273. */274. String.prototype.isShortDate=function()

16、275. 276. varr=this.replace(/(s*)|(s*$)/g,).match(/(d1,4)(-|/)(d1,2)2(d1,2)$/); 277. if(r=null) 278. 279. returnfalse; 280. 281. vard=newDate(r1,r3-1,r4); 282. return(d.getFullYear()=r1&(d.getMonth()+1)=r3&d.getDate()=r4); 283. 284. 285. /* 286. = 287. /是否是正确的日期 288. = 289. */290. String.prototype.i

17、sDate=function() 291. 292. returnthis.isLongDate()|this.isShortDate(); 293. 294. 295. /* 296. = 297. /是否是手机 298. = 299. */300. String.prototype.isMobile=function() 301. 302. return/00,1130-99$/.test(this); 303. 304. 305. /* 306. = 307. /是否是邮件 308. = 309. */310. String.prototype.isEmail=function() 31

18、1. 312. return/w+(-w+)|(.w+)*A-Za-z0-9+(.|-)A-Za-z0-9+)*.A-Za-z0-9+$/.test(this); 313. 314. 315. /* 316. = 317. /是否是邮编(中国) 318. = 319. */320. 321. String.prototype.isZipCode=function() 322. 323. return/d6$/.test(this); 324. 325. 326. /* 327. = 328. /是否是有汉字 329. = 330. */331. String.prototype.existChinese=function() 332. 333. /u4E00-u9FA5為漢字uFE30-uFFA0為全角符號 334. return/x00-xff*$/.test(this);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1