I am trying to split my current applications version number, but is removes the leading zeros.
How do i change my split to not remove the leading zeros.
Getting the currentVersionNo:
startUpAssembly.GetName().Version.ToString()
So for testing:
string versionNo = "7.01.7000.0";
string[] versionInfo = versionNo.Split('.');
This produces:
7
1 //Here i need it to be 01
7000
0
And i need it to NOT remove the leading zero. How do i achieve this?
Maybe there is a better solution using regex?
A
System.Versionisn’t an arbitrary string – it’s four integers. Leading zeroes are irrelevant, so not included when converting back to a string. That’s where you’re losing information – not inString.Split. You can see this very easily:Basically, your plan is fundamentally flawed, and you should change your design. You shouldn’t be trying to represent a version of “7.01.7000.0” to start with.
Additionally, you should take a step back and think about your diagnostic procedure: what made you think that
String.Splitwas to blame here? Why wasn’t your first step looking at the result ofstartUpAssembly.GetName().Version.ToString()?