There is a file with the text:

<координата x1> <координата y1> <координата x2> <координата y2> <координата x3> <координата y3> <координата x4> <координата y4> 

I need to split up all the unnecessary and leave only the numbers, BUT when downloading a file and outputting it to the console, it gives out a bunch of questions without understanding Russian letters. This is problem number one. Problem number 2: how to split off by cutting off the whole word without spelling it?

well, and the code itself, I'm new so do not swear and take notes to all listen properly

  string text = File.ReadAllText("test.txt"); string[] coords = text.Split(' ', '\n', 'x', 'y', '<', '>', 'к', 'о', 'р', 'д', 'и', 'н', 'а', 'т'); int x1 = Convert.ToInt32(coords[0]); int y1 = Convert.ToInt32(coords[1]); int x2 = Convert.ToInt32(coords[2]); int y2 = Convert.ToInt32(coords[3]); int x3 = Convert.ToInt32(coords[4]); int y3 = Convert.ToInt32(coords[5]); int x4 = Convert.ToInt32(coords[6]); int y4 = Convert.ToInt32(coords[7]); Console.WriteLine("введите значение Х: "); int xP = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("введите значение Y: "); int yP = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(text + coords[1] +" "); Console.ReadLine(); 
  • And why not RegEx ? Choose numbers by sawing off another - Aleksey Shimansky

2 answers 2

Try using the overloaded File.ReadAllText method with the original encoding.

  • as? can I write code? i don't understand - kross
  • In the link there are examples of use, everything is quite transparent. At least try. - Aleksandr Zharinov
  1. As already suggested, try regular expressions. Like that:

     void Main() { var strings = new List<string>(); strings.Add("<координата x1565> <координата y1234>"); strings.Add("<координата x243> <координата y2442>"); strings.Add("<координата x343> <координата y34433>"); //Условие по которому искать. //Нужные блоки выделяются скобками, чтобы потом найти их через группы var pattern = @"<координата x(\d+[.,]?\d+)> <координата y(\d+[.,]?\d+)>"; foreach(var str in strings) { Match match = Regex.Match(str, pattern); //Группа с индексом 0 - это само найденное выражение. //Координата Х - индекс группы 1 //Координата У - индекс группы 2 Console.WriteLine(string.Format("x: {0}, y: {1}", match.Groups[1], match.Groups[2])); } } 
  2. Questions on the console. Most likely the file is in your win1251 encoding, and the console is in unicode. Convert the file to another encoding.