我有一串单词(它们由换行符分隔)
aa
aaa
aaaa
aaaaa
我想将它添加到数组“words”
[1] = aa
[2] = aaa
[3] = aaaa
[4] = aaaaa
我怎样才能在 ionic 2 中做到这一点?我知道在java中它看起来像这样
String s = "This is a sample sentence.";
String[] words = s.split("\\s+");
for (int i = 0; i < words.length; i++) {
words[i] = words[i].replaceAll("[^\\w]", "");
}
但在 ionic 2 中无法弄清楚。
最佳答案
在 Javascript 或 Typescript 中,您可以执行相同的操作:
const s = "This is a sample sentence.";
const words = s.split(" ");
// displaying the array
for (word of words){
console.log(word);
}
关于javascript - ionic 2 - 将句子字符串转换为单词数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48129046/