MATLAB: How to divide up a string according to a recurring number

前端 未结 1 1753
暖寄归人
暖寄归人 2021-01-25 10:07

Good day.

Here is an example of a piece of literate I want to divide up:

str =      ["1 This is sentence one of verse one, "+ ...
            &qu         


        
相关标签:
1条回答
  • 2021-01-25 11:01

    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!"
    
    0 讨论(0)
提交回复
热议问题