假设我的textarea有这个字符串:
一个长期存在的事实是读者会分心。通过 在查看其布局时,页面的可读内容 使用Lorem Ipsum是因为它具有或多或少的正态分布 字母,而不是使用。
我想在用户输入textarea时自定义此字符串。
输出字符串应如下所示:
İ t是一个长期存在的事实,读者会分心。 B y 查看其布局时页面的可读内容。 T 他指出 使用 l orem Ipsum是因为它具有或多或少的正态分布 字母,而不是使用。
我该怎样做以及regular expression是什么类型的?
答案 0 :(得分:0)
我不确定这是您想要的解决方案,但首先,您可以使用:
var text = 'it is a long established fact that a reader will be distracted. by the readable content of a page when looking at its layout.the point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters,as opposed to using.';
var r = /\.\s?/;
var sentences = text.split(r);
var desiredResult = new Array();
for (var i = 0; i < sentences.length; i++) {
if (sentences[i].length > 0) {
var fixedSentence = sentences[i][0].toUpperCase() + sentences[i].substr(1).toLowerCase();
if (i > 0 && sentences[i][0] != ' ') {
fixedSentence = ' ' + fixedSentence;
}
desiredResult.push(fixedSentence);
console.log(fixedSentence);
}
}