提取特定的字符串整型 [英] extract specific string & int

查看:117
本文介绍了提取特定的字符串整型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有列表"变量,其中包含--ASW+90s, 160, 160S, M45s, 130.5. R+129.
之类的值
我想知道如何提取字符串,例如160s和R + 129.
到目前为止,这是我的尝试,但是我一直遇到编译错误:

I have ''list'' variable, which contains values such as - ASW+90s, 160, 160S, M45s, 130.5. R+129.

I would like to know, how can I extract strings such as 160s and R+129.
Here is my attempt so far, but I keep experiencing compiling errors:

else if (Int32.TryParse(list, out i))
                               {
                                   string b = "";
                                   b += list == "S";
                                   if (Math.Abs(i) >= 125 && b)
                                   {
                                       string a = "";
                                       a += i.ToString();
                                       row["Value"] = a;
                                   }
                               }



如果有人可以帮助定义,则进一步执行此任务所需的逻辑将对继续前进有很大帮助.

任何帮助,不胜感激.
谢谢



if someone could help to define, the logic required to implement this task further, that would be a great help, to progress forward.

Any help much appreciated.
Thanks

推荐答案

在这里:
var str = "ASW+90s, 160, 160S, M45s, 130.5, R+129";
var list = str.Split(new string[] {", "}, StringSplitOptions.RemoveEmptyEntries);

var re1 = new Regex(@"^[A-Za-z]\+\d+


"); var re2 = 正则表达式( @" ^(\ d +)[sS]
"); var re2 = new Regex(@"^(\d+)[sS]


"); var 结果= 来自元素 列表中的元素 m2 = re2.Match(element) 其中 re1.Match(element).Success || (m2.成功&& int .Parse(m2.Groups [ 1 ].Value)> 125 ) 选择元素; result.Dump();
"); var result = from element in list let m2 = re2.Match(element) where re1.Match(element).Success || (m2.Success && int.Parse(m2.Groups[1].Value) > 125) select element; result.Dump();


这不是纯正则表达式,因为我将语义验证用于第二个条件.并且它正在处理具体的列表/数组,但是如您所见,将字符串拆分为列表/数组非常简单.


This is not pure-regexp, as I am using semantic validation for the second criteria. And it is working on a concrete list/array, but as you can see it is quite simple to split the string into a list/array.


这篇关于提取特定的字符串整型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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