Extract version number from string(eg : “ver.1.9.0”)

后端 未结 3 568
盖世英雄少女心
盖世英雄少女心 2021-01-29 05:19

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

3条回答
  •  猫巷女王i
    2021-01-29 06:09

    Here you go:

    using System;
    using System.Text.RegularExpressions;
    
    namespace RegVer {
        class Prog {
            static void Main() {
                var verstring = "ver:1:9.5";
                var dotVerString = verstring.Replace(':','.');
                Console.WriteLine(Regex.Match(dotVerString, @"ver\.([\d\.]+)").Groups[1].Value);
            }
        }
    }
    

    Or if you want array with each version digit.

    using System;
    using System.Text.RegularExpressions;
    
    namespace RegVer {
        class Prog {
            static void Main() {
                var verstring = "ver:1:9.5";
                var VerABC = Regex.Matches(verstring, @"\d");
                Console.WriteLine("a = " + VerABC[0] + "\n" +
                                  "b = " + VerABC[1] + "\n" +
                                  "c = " + VerABC[2]);
            }
        }
    }
    

提交回复
热议问题