Search code examples
c#jagged-arrays

C# - copying from a jagged array to a jagged array with data changes


I want to take the phrases that are stored in jagged array number one to break those phrases into individual words and put them into another jagged array. how to make it work?

I was able to put the data from a one-dimensional array into a jagged array, that is, break the sentence into phrases:

string[][] phrases;
{
  phrases = new string[sentences.Length][];
  char[] charRemover = { ',', ':' };

  for (int i = 0; i < sentences.Length; i++)
  {
     phrases[i] = sentences[i].Split(charRemover);
  }
}

but I could not break the phrases into words, that is, put the data from one gear array into another! tell me please how to do it

Full code


Solution

  • I found a way to copy the data of a gear array to another gear with the data changes

    string[][] phrases;
            {
                phrases = new string[sentences.Length][];
                char[] charRemover = { ',', ':' };
                for (int i = 0; i < sentences.Length; i++)
                {
                    phrases[i] = sentences[i].Split(charRemover);
                }
            }
    
            string[][] words;
            {
                words = new string[phrases.Length][];
    
                for (int y = 0; y < phrases.Length; y++)
                {
                    // Initialize Array
                    words[y] = new string[phrases[y].Length];
                    // For each Column
                    for (int x = 0; x < words[y].Length; x++)
                    {
                        words[y][x] = phrases[y][x].Replace(" ", "");
                    }
                }
            }