问题描述
美好的一天。
这是我想分开的一个识字的例子:
str = ["1 This is sentence one of verse one,"+ ...
"2 This is sentence one of verse two. "+ ...
"3 This is sentence two of verse three; "+ ...
"1 This is sentence three of verse one? "+ ...
"2 This is sentence four of verse two,"+ ...
"3 this is sentence four but verse three!"];
请注意数字是如何重新开始的,这表示新的章节已开始。我如何制作一个nx1字符串,其中n =章节。结果如下所示:
我们非常感谢您的帮助。 谢谢!
解决方法
您只需要一点字符串操作即可:
>> c=convertStringsToChars(str);
>> splitstring = split(str,c(1));
>> splitstring = splitstring(strlength(splitstring) > 0);
>> formattedstring = string(1:length(splitstring)).' + " " + c(1) + splitstring
formattedstring =
2×1 string array
"1 1 This is sentence one of verse one,2 This is sentence one of verse two. 3 This is sentence two of verse three; "
"2 1 This is sentence three of verse one? 2 This is sentence four of verse two,3 this is sentence four but verse three!"