I am attempting to read in from a txt file strings that are very similar to the following:
YXCZ0000292=TRUE
or
THS83777930=FALSE
I need to use string split to collect a serial number and put it into a variable I can use later as well as use the true or false portion of the string to set a check box. The serial numbers will never be the same and the TRUE or FALSE portion can be random. Anyone have a good way to handle this one?
Given any string called line, you should be able to do
var parts = line.Split('=');
var serial = parts[0];
var boolean = bool.Parse(parts[1]);
I'm thinking that should work as needed.
string s = "THS83777930=FALSE";
var parts = s.Split( '=' );
// error checking here, i.e., make sure parts.Length == 2
var serial = parts.First();
var booleanValue = parts.Last();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With