怎么做以下? [英] how to do the following?

查看:98
本文介绍了怎么做以下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串filepath =F:\ first_folder \Node3_V_1.3



i有一个名为version_check的按钮



点击此按钮我想打印消息将Node3升级到版本1.3(其详细信息从字符串文件路径获取)。我如何在C#中编码。

请帮帮我。





1)要获取的文件采用标准格式: Nodex_V_x.x,其中x将在1-7范围内。

2)变量filepath的长度动态变化(取决于选择它的路径)

解决方案

试试一个正则表达式:

(?< FromVer> \d(\。\ d)?)_ V _(?< ToVer> \d(\。\ \\ d)?)


应该这样做。

如果你想将数字限制在1到7之间,那么替换 \dwith[1-7]贯穿始终。





什么是正则表达式?我不知道这个。我想要上面提到的问题的代码,因为我是c#



正则表达式是正则表达式解析器的缩写它是一个从字符串中提取信息位的工具。在这种情况下,它会进行一些简单的模式匹配,并从路径字符串中获取所需的信息。



获取快餐 [ ^ ] - 它是免费的,它会检查并生成正则表达式。



它还会为您生成C#代码!

  public   static 正则表达式findVersions =  new 正则表达式( (?< FromVer> [1-7](\\。\ ?\d))_ V _(小于?TOVER> \\d(\\.\\d))

)?;
...
匹配m = findVersions.Match(filepath);
if (m.Success)
{
string fromVer = m.Groups [ FromVer]。值;
string toVer = m.Groups [ TOVER]值。
...
}


i have a string filepath = "F:\first_folder\Node3_V_1.3"

i have a button named version_check

on the click of this button i want to print the message "UPGRADING Node3 to Version 1.3"(whose details are fetched from string filepath). how do i code this in C#.
please help me out.


1)the file to be fetched is in the standard format : Nodex_V_x.x, where x will be in the range 1-7.
2) the length of the variable filepath changes dynamically( depends on the path from where it is selected)

解决方案

Try a regex:

(?<FromVer>\d(\.\d)?)_V_(?<ToVer>\d(\.\d)?)


Should do it.
If you want to restrict numbers to just 1 to 7, then replace "\d" with "[1-7]" throughout.


"what is regex? i m not aware of this . i want the code for the above mentioned problem since am very new to c#"

"Regex" is short for "Regular Expression Parser" and it is a tool for extracting "bits" of information from a string. In this case, it does some simple pattern matching and gets the info you want from the path string.

Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.

It also generates C# code for you!

public static Regex findVersions = new Regex("(?<FromVer>[1-7](\\.\\d)?)_V_(?<ToVer>\\d(\\.\\d)?)


"); ... Match m = findVersions.Match(filepath); if (m.Success) { string fromVer = m.Groups["FromVer"].Value; string toVer = m.Groups["ToVer"].Value; ... }


这篇关于怎么做以下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆