admin管理员组文章数量:1309939
Im trying to split a sting variable into an array with each character in its own position in the array, but cant seem to get this to work
function test() {
var strString = "thisIsTheString";
var test = @Explode(strString, "");
var strReturn = "";
for (var i = 0; i < @Length(test); i++) {
strReturn += test[i] + "<br/>";
}
return strReturn;
}
Im trying to split a sting variable into an array with each character in its own position in the array, but cant seem to get this to work
function test() {
var strString = "thisIsTheString";
var test = @Explode(strString, "");
var strReturn = "";
for (var i = 0; i < @Length(test); i++) {
strReturn += test[i] + "<br/>";
}
return strReturn;
}
Share
Improve this question
edited Jul 10, 2013 at 13:39
Naveen
6,93610 gold badges41 silver badges85 bronze badges
asked Jul 10, 2013 at 12:11
Hosea KambondeHosea Kambonde
3011 gold badge4 silver badges13 bronze badges
2
-
Maybe you can use
split
instead ofexplode
? – Pieter Commented Jul 10, 2013 at 12:25 - 2 You have tagged this question Lotusscript but your code snippet is not Lotusscript but rather server-side JavaScript :-) – Per Henrik Lausten Commented Jul 10, 2013 at 12:39
2 Answers
Reset to default 8The simplest way would be to use split
function by passing empty string to it. For e.g.
var str = "this is a string";
var arr = str.split("");
@Explode uses as delimiters space, ma and semicolon if second parameter is empty. That doesn't help you in your case. Just use "normal" string functions like substring()
:
function test() {
var strString = "thisIsTheString";
var strReturn = "";
for (var i = 0; i < strString.length; i++) {
strReturn += strString.substring(i, i+1) + "<br/>";
}
return strReturn;
}
In case you really need an array of characters then code would look like this:
var strString = "thisIsTheString";
var arrayReturn = new Array();
for (var i = 0; i < strString.length; i++) {
arrayReturn[i] = strString.substring(i, i+1);
}
版权声明:本文标题:javascript - Split all characters in a string with no delimiter into an array with lotus notes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741839660a2400420.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论