我有短信。根据一些正在印刷的书,文本有不同的行号。我的应用程序也需要这样显示。例如。:
1 This is a sentence. Here is another. The third sentence 1
2 stretches over multiple lines and is only completed in 2
3 line number 3. Then we have a fourth and fifth sentence, 3
4 but then that's it. That's it. 4
文本需要保存在某个后端的某个地方。我可以逐行保存整个文本:
text = {
{
line_no: 1,
content: "This is a sentence. Here is another. The third sentence",
},
{
line_no: 2,
content: "stretches over multiple lines and is only completed in",
},
etc...};
一句话
而且几乎从不使用线条,除非我需要在屏幕上呈现文本。所以假设我需要保存一个特定句子的字数。将文本分成句子会容易得多:
{
sentence_no: 1,
content: "This is a sentence.",
word_count: 3
},
{
sentence_no: 2,
content: "Here is another.",
word_count: 3
},
{
sentence_no: 3,
content: "The third sentence stretches over multiple lines and is only completed in line number 3. ",
word_count: 15
},
etc....
我正在努力理解如何使用后一种方法(或类似的方法),并且仍然在某处保存行号。我将非常感谢你的建议!