Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncating a version number C#

Tags:

c#

.net

version

If I have a version number that has 5 digits such as "1.0.420.50.0", how could I truncate this number (and other version numbers like "1.0.512.500.0") to only 4 digits? "1.0.420.50.0" --> "1.0.420.50"

I would prefer to use an array but any other methods work too! Thanks for any advice in advance!

like image 907
Scott Avatar asked Aug 06 '15 18:08

Scott


1 Answers

I haven't programmed in c# in a while so the syntax may be off. If the versioning can be more than six digits, you won't want a method that relies on removing the last digit. Instead just take the first four version numbers.

String version = "1.0.420.50.0";
String [] versionArray = version.Split(".");
var newVersion = string.Join(".", versionArray.Take(4));
like image 124
Speerian Avatar answered Sep 18 '22 17:09

Speerian