Question

I have a string s which stores a very long sentence and I want to copy the content of s to an array C with each cell storing a sentence each. The following is my code which is not giving me any output, but the dimension of the cell:

while(i<6)
  C(i)=s;
  end

This is how I get as output when I print C:

C=
[1x76 char]

Can somebody please help me.

Était-ce utile?

La solution 2

Suppose Long string is:

longString = "This is first cell. This is second cell. this is third cell".

Now since . is delimiter here means it is acting as separator for sentences. so you can loop through longString character wise and whenever you encounter a . you just increase Array index count and keep storing in this Array index until you find another .

here is sudo code:

array[];
index = 0;
loop through(longString) character wise
{
if(currentChar equals  to '.')
{
index++;
}
else
{
array[index] = currentChanracter;
}
}

Autres conseils

Another job for 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.'

We are specifying a period followed by a space as the delimiter. Change this as needed.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top