解析动态URL的数据

时间:2023-02-08 20:36:07

I am working on creating a link to help documents. The link is set up to get the URL string (server info) and then append the version string onto the end of it.

我正在创建一个帮助文档的链接。设置链接以获取URL字符串(服务器信息),然后将版本字符串附加到其末尾。

The problem that I am having is that we keep track of our version using a 4 digit system with each digit having a specific meaning, but the links to the help documents only use the first 3 digits.

我遇到的问题是我们使用4位数系统跟踪我们的版本,每个数字具有特定含义,但是帮助文档的链接仅使用前3位数字。

Is there a way to edit the version# that I am getting so that it only includes the first 3 digits when I add it to the URL?
example:
Version # 2.4.5.345
URL: ServerURLHere/version-2.4.5

有没有办法编辑我正在获取的版本#,以便在我将其添加到URL时仅包含前3位数字?示例:版本号2.4.5.345 URL:ServerURLHere / version-2.4.5

This is getting the version #

这是获得版本#

private void SetApplicationVersion()
    {
        var assembly = Assembly.GetExecutingAssembly();
        var versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
        Application["__application_version__"] = versionInfo.FileVersion;
    }

This sets the first part of the URL

这将设置URL的第一部分

<add key="Help_URL" value="ServerURLHere/version-" />

This creates the URL that is used. This is where I am wondering if it is possible to limit the application version to a 3 digit set instead of using all 4.

这将创建使用的URL。这就是我想知道是否可以将应用程序版本限制为3位数而不是全部4位。

var help = new Help({ Help_URL: '@System.Configuration.ConfigurationManager.AppSettings["Help_URL"]' + '@HttpContext.Current.Application["__application_version__"]' });

1 个解决方案

#1


If your concern is possible version numbers with more than one digit (2.42.1045 for example), you can use split and concat to be sure you'll grab the full version:

如果您担心的是可能的版本号超过一位数(例如2.42.1045),您可以使用split和concat来确保您获取完整版本:

string version = "2.42.1045.3434";
string[] proc = version.Split('.');
version = string.Concat(proc[0], ".", proc[1], ".", proc[2]);
Console.Write(version);

Another alternative is to use Substring and LastIndexOf:

另一种方法是使用Substring和LastIndexOf:

version = "2.42.1045.3434";            
Console.Write(version.Substring(0, version.LastIndexOf('.')));

#1


If your concern is possible version numbers with more than one digit (2.42.1045 for example), you can use split and concat to be sure you'll grab the full version:

如果您担心的是可能的版本号超过一位数(例如2.42.1045),您可以使用split和concat来确保您获取完整版本:

string version = "2.42.1045.3434";
string[] proc = version.Split('.');
version = string.Concat(proc[0], ".", proc[1], ".", proc[2]);
Console.Write(version);

Another alternative is to use Substring and LastIndexOf:

另一种方法是使用Substring和LastIndexOf:

version = "2.42.1045.3434";            
Console.Write(version.Substring(0, version.LastIndexOf('.')));