Having a brain stumble today. Needing to extract a number from a string.
Example: 8 UP, and I need the number 8. It can also be 35 UP and I would need the 35.
Having a brain stumble today. Needing to extract a number from a string.
Example: 8 UP, and I need the number 8. It can also be 35 UP and I would need the 35.
is the format always going to be Number + space + “UP”? If so, I would suggest creating a split operation with the space as a separator, and your first value in the array returned would be your number, and you can convert that from string to int. If the format is always the same, I can give you the code I use for splitting a string.
Yes, it is the same format for these parts. That would be great if you are willing to share the code.
string yourvalue = "8 UP";
string[] separators = {" "};
string[] x = yourvalue.Split(separators, StringSplitOptions.RemoveEmptyEntries);
int yournumber = Convert.ToInt32(x[0]);
There it is. Replace yourvalue variable with whatever you are using. the separators in this example is a space, but, you can use anything in the future. Example, you could have value 1/2, and have the separator be “/”, x[0] would be 1, and x[1] would be 2. Hope this helps!