-1

I have a task. I should extract two substrings from a string. The lenght of the String will be different each time, so the method should be generic.

Suppose I have the following String:

/*Description:\r\n*RANGE:\r\n*HIGH\r\n*LOW\r\n*/

I need to get the substring1= HIGH and substring2= LOW. The substring1 and substring2 will be all the time between \r\n, but they values will be different.

I would be very grateful if anybody helps me. It can be a pseudocode, anything.

Thanks in advance.

UPDATE1: I'm searching first for "RANGE:\r\n*" and get the index of the character * and the index og character "H". But next don't know how to get the whole substring.

JNevill
  • 46,980
  • 4
  • 38
  • 63
Felix J.
  • 33
  • 4

1 Answers1

0

If the pattern you've provided is similar to what you'd expect all the time, a stupid simple approach would be:

public static string[] GetParts(string input)
{
    string[] parts= input.Split("\r\n", StringSplitOptions.RemoveEmptyEntries);
    return parts.TakeLast(2).Select(item=>item.Replace("*", string.Empty)).ToArray();
}

Note: This is not a production quality code.

Artak
  • 2,819
  • 20
  • 31