admin管理员组文章数量:1402943
I have some word have to split, but how can i split two things using one time only ? Example, "avg/hulk.swf" and "dance.swf"
both I only need their name hulk
and dance
, How to write split jquery in one time to split avg/
and .swf
that I want ? Because all get from DB , so some contain avg/
and .swf
some only .swf
.
var test = "avg/hulk.swf";
var keyword = test.split("avg/")[1];
alert(keyword);
<script src=".1.1/jquery.min.js"></script>
<div class="show"></div>
I have some word have to split, but how can i split two things using one time only ? Example, "avg/hulk.swf" and "dance.swf"
both I only need their name hulk
and dance
, How to write split jquery in one time to split avg/
and .swf
that I want ? Because all get from DB , so some contain avg/
and .swf
some only .swf
.
var test = "avg/hulk.swf";
var keyword = test.split("avg/")[1];
alert(keyword);
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="show"></div>
Share
Improve this question
asked Apr 10, 2015 at 8:01
FeelRightzFeelRightz
2,9992 gold badges43 silver badges80 bronze badges
2
- you go to regular expression – Sudharsan S Commented Apr 10, 2015 at 8:05
- so your problem is that keyword sometimes contains ".swf"? Why not use an other split to get rid of that the same way you got rid of "avg/"? – doldt Commented Apr 10, 2015 at 8:06
4 Answers
Reset to default 2Try to remove them from string.
var test = "avg/hulk.swf";
var keyword = test.replace(/avg\/|\.swf/g,'');
alert(keyword);
try this.
you can use split()
then pop()
andslice()
after
function getName(path){
return (path.split('/').pop()).slice(0,-4);
}
alert( getName("dance.swf") + "\n" + getName("avg/hulk.swf"));
SEE DEMO
its only works for your given context.
var test = "avg/hulk.swf";
var keyword = test.split("avg/")[1].split(".")[0];
alert(keyword);
Fiddle
1 var str = "JQUERY By Example";
2 var n = str.charAt(2)
//Output will be "U"
so yeah here is an example for 1 letter, and here is if you want to get a specific word:
var str="Hello world!";
var n=str.substr(2,3)
//Output will be "llo"
Hope this helps!
本文标签: javascriptSplit word jqueryStack Overflow
版权声明:本文标题:javascript - Split word jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744303305a2599686.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论