if i pass a string (verstring == \"vername.1.19.5\") it will return the version because i am ignoring Currentver[0]. if i want to pass verstring == \"1.19.5\".
I mean i
If you are opened to use Regex
, the answer below might help you:
var regexPattern = @"(?:ver\:)?(?\d)[\.|\:](?\d)[\.|\:](?\d)";
var regex = new Regex(regexPattern);
var match = regex.Match("1:2.3");
var major = Convert.ToByte(match.Groups["major"].Value);
var minor = Convert.ToByte(match.Groups["minor"].Value);
var revision = Convert.ToByte(match.Groups["revision"].Value);
It uses regex named groups in order to retrieve the value versions. You can change the group name as part of the regex by a,b,c if you prefer and you would get something like this:
var regexPattern = @"(?:ver\:)?(?\d)[\.|\:](?\d)[\.|\:](?\d)";
var regex = new Regex(regexPattern);
var match = regex.Match("1:2.3");
var a = Convert.ToByte(match.Groups["a"].Value);
var b = Convert.ToByte(match.Groups["b"].Value);
var c = Convert.ToByte(match.Groups["c"].Value);