我有一个字符串s
,它存储一个很长的句子,我想将s
的内容复制到数组C
,每个单元格都存储一个句子。以下是我的代码,它没有给我任何输出,而是单元格的维度:
while(i<6)
C(i)=s;
end
这是我打印C
时的输出方式:
C=
[1x76 char]
请有人帮助我。
答案 0 :(得分:5)
strsplit
的另一项工作:
>> sentences = 'This is the first one. Then here is a second. Yet another here.';
>> C = strsplit(sentences,'. ')
C =
'This is the first one' 'Then here is a second' 'Yet another here.'
我们指定一个句点,后跟一个空格作为分隔符。根据需要进行更改。
答案 1 :(得分:0)
假设长字符串是:
longString = "This is first cell. This is second cell. this is third cell".
现在.
是分隔符,这意味着它充当了句子的分隔符。所以你可以通过longString
字符循环,每当遇到.
时,你只需增加数组索引计数并继续存储在这个数组索引中,直到找到另一个.
这是sudo代码:
array[];
index = 0;
loop through(longString) character wise
{
if(currentChar equals to '.')
{
index++;
}
else
{
array[index] = currentChanracter;
}
}