如何在不删除定界符的情况下拆分字符串?
假设我有一个字符串: var string = "abcdeabcde";
var string = "abcdeabcde";
当我这样做时 var newstring = string.split("d"),我得到的是这样的:
var newstring = string.split("d")
["abc","eabc","e"]
但我想得到这个:
["abc","d","eabc","d","e"]
当我尝试执行“ split2”功能时,我都陷入了splice()和索引以及“ this” vs“ that”和… aargh的纠结之中!帮帮我!:D
尝试这个:
用“,”分隔
var string = “abcdeabcde”; var newstringreplaced = string.replace(/d/gi, “,d”); var newstring = newstringreplaced.split(“,”); return newstring;
希望这可以帮助。