There is a text file in which the text of this type: X56373Y57483W46373H4747A0 .

Is it possible in C # to pull the values ​​in turn from the proposed line, for example X56373 , then separately Y57483 and W46373 ? If so, how?

  • split into lines of 6 characters or what? - Ruslan_K
  • 6
    for example using the regulars: Regex.Matches(s, @"\w\d+") - Grundy
  • one
    And by what criterion to break? According to the letter? - VladD
  • The line needs to be broken down into tweaks, I think. And split by the criterion. X, Y, W. But the whole problem is that besides X there are numbers ... Therefore, it is necessary to divide by the criterion X and by the set of numbers after each letter X, Y, W, etc. .. - Jeron
  • 2
    @Jeron Regularly and divided into groups. Then, turning to each group, parse the values. - free_ze

2 answers 2

Here is one of the options:

 string input = "X56373Y57483W46373H4747A0"; string pattern = @"(X\d+)|(Y\d+)|(W\d+)"; Regex regex = new Regex(pattern); MatchCollection matches = regex.Matches(input); foreach (Match match in matches) { Console.WriteLine(match.Value); } 

    You can try this:

     string text = @"X56373Y57483W46373H4747A0"; Regex regex = new Regex(@"[AZ]\d+"); var matches = regex.Matches(text); 
    • Not sure if you need a \D - Grundy
    • @Grundy, now checked, really \ D does not work, corrected the answer. - Mirdin