首页 > 编程语言 > 详细

从字符串里提取一个列表(数组)

时间:2017-08-03 11:01:48      阅读:203      评论:0      收藏:0      [点我收藏+]

var santent=‘this is one santent. this is a santent with a list of items:‘+‘cherries,oranges,apples,bananas. that was the list of items.‘;  //创建一个字符串
var start = santent.indexOf(‘:‘);  //找到要提取列表开始位置
var end = santent.indexOf(‘.‘,start+1); //找到要提取列表的结束位置
var liststr=santent.substring(start+1,end);//通过substring提取中间的字符
var fruits=liststr.split(‘,‘);//split通过逗号分隔字符串成为数组

console.log(fruits);

从字符串里提取一个列表(数组)

原文:http://www.cnblogs.com/thybk/p/7278385.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!