I have some strings that are like FFS\D46_24\43_2 I want to return the text between the first backslash and last underscore. In case of above example, I want to get D46_24\43
I tried the code below but it throws argument out of range exepction:
public string GetTestName(string text)
{
return text.Remove(
text.IndexOf("\\", StringComparison.InvariantCultureIgnoreCase)
,
text.LastIndexOf("_", StringComparison.InvariantCultureIgnoreCase)
);
}
The second parameter is a count, not an ending index. Additionally, the correct method to isolate part of a string is
Substringand notRemove. So you have to write it as