MATLAB:如何根据重复编号对字符串进行除法 [英] MATLAB: How to divide up a string according to a recurring number
本文介绍了MATLAB:如何根据重复编号对字符串进行除法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天。
以下是我想分开的一个识字的例子:
Here is an example of a piece of literate I want to divide up:
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 =章节。结果应该是这样的:
Notice how the numbers start over, this indicates a new chapter started. How can I make a nx1 string where n=chapters. This is what the results should look like:
我们非常感谢您的帮助。
谢谢!
Help is appreciated. Thanks!
推荐答案
您只需要一点字符串操作:
You only need a little bit of string manipulation:
>> 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!"
这篇关于MATLAB:如何根据重复编号对字符串进行除法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文