Separate the strings by 2 variables



  • I have a mass:

    string[] command = new string[] { "возьми", "эти", "таблетки", "*", "передавая", "таблетки", "пациенту" };
    

    We need two variables at the end:

    var first = "возьми эти таблетки";
    var second = "передавая таблетки пациенту";
    

    "*" is a divider between the first and second part. He can be in any part of the body. I need the code to find it myself. Also, words in the body can change.



  • string[] command = new string[] { "возьми", "эти", "таблетки", "*", "передавая", "таблетки", "пациенту" };
    
    var results = string.Join(" ", command).Split(new[] { " * " }, StringSplitOptions.None);
    if (results.Length < 2)
    {
        throw new ArgumentException(nameof(command));
    }
    
    var first = results[0];
    var second = results[1];
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2