I need to split an input value high/low that might come in three different forms: 120/50, 120/, /50, 120.
I would like to split this into two different variables and check the values I got.
var high = input.Split('/').First();
var low = input.Split('/').Last();
if (high.Length > 0) //Do this
if (low.Length > 0) //Do that
The problem is that with the two last inputs I get the same value in both high and low. Which means I can’t tell if I got a high value or a low.
I’m starting to suspect I can’t use split here?
EDIT
It seems as if there are values with no / at all. Those values should be interpreted as high values.
You could use
NullablesandTryParsewhich is safer:Now you can check if they are set with the
HasValueproperty, for example: