简体   繁体   中英

How to not display the latest version if current version has more than 2 digits?

Below are my coding on getting the current version and all the latest version of folder, if my current version displays more than 2 digit for example 3.24.10, how to not display the latest version.

// Gets current version.
using (StreamReader str = new StreamReader(file))
{
    txt = str.ReadToEnd();
}

if (txt.Contains("TEST"))
{
    int iStartIndex = txt.LastIndexOf("TEST") + 17;
    for (int i = 0; i < 50; i++)
    {
        if (txt[iStartIndex + i] == '>')
            break;
        currentRelease += txt[iStartIndex + i];
    }
}

// Gets latest version.
if (Directory.Exists(txtBoxPRJ_RELPath.Text))
{
    string path = @"C:\Users\kwding\Desktop\Tool\ECHS\Soft\PRJ_REP\NTI\Cmp\NTIm";
    string latestModuleDir = System.IO.Path.Combine(path, System.IO.Path.GetFileNameWithoutExtension(file));
    if (Directory.Exists(latestModuleDir))
    {
        string[] latestversions = Directory.GetDirectories(latestModuleDir);
        Array.Sort(latestversions, new AlphanumComparatorFast());
        latestRelease = System.IO.Path.GetFileName(latestversions.Last());
    }
}

Find the last dot in the string and check how many characters after that dot. If they're more than two then cut it.

var temp = text.SubString(text.LastIndexOf('.') + 1);
if(temp.Lengths > 2)
{
    temp = temp.SubString(0,2);
    text = text.Substring(0,text.LastIndexOf('.')) + temp;
}

Something like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM