There is a string that is not quite simple.

" Книги Учебная литература Дошкольникам Общая подготовка к школе " 

How do i make an array of it? The first word begins after four spaces, then the rest after 7. It should turn out like this

 array[0] = "Книги" array[1] = "Учебная литература" и тд 

and the length of the string may be different. An array for this purpose?

  • str.Trim().Split(new string[] {" "}, StringSplitOptions.None); - there are 7 spaces between quotes - Igor
  • It also did not help. - shatoidil
  • It helped, you copied the wrong code :) - Igor
  • Maybe your columns are divided by position? Very similar to this. - mals 4:39 pm

2 answers 2

 string str = " Книги Учебная литература Дошкольникам Общая подготовка к школе "; string[] items = str.Trim().Split(new string[] {" "}, StringSplitOptions.None); // между кавычками 7 пробелов 
  • Does not work. Each word is entered into a separate cell of the array, plus all spaces - shatoidil
  • @shatoidil // 7 spaces between quotes - Igor
  • Everything worked! Excellent - shatoidil

Try for example like this:

 string str = " Книги Учебная литература Дошкольникам Общая подготовка к школе "; var arr = str.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray(); 
  • array[1] = "Учебная литература" - Igor
  • Yes, he shares every word - shatoidil
  • @shatoidil corrected, look - DreamChild
  • @DreamChild Yes, every word also falls into a separate cell of the array, and it would be necessary for array [1] = "Training Literature" to be like this. That is, let him ignore a single space, and remove more than one timidly - shatoidil
  • @shatoidil you check. It works fine. There, the splitting into lines occurs not one by one, but by two spaces - DreamChild