System.Text.RegularExpressions ... [英] System.Text.RegularExpressions...

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

问题描述

大家好,



i想要满足条件,如果rawValue包含文本或Empty.but它给我错误

错误15' System.Text.RegularExpressions.Regex'是'type',但用作'变量'



Hi Everyone,

i want to satisfy the condition if rawValue contains text or Empty.but its give me error
Error 15 'System.Text.RegularExpressions.Regex' is a 'type' but is used like a 'variable'

public static string ExtractValue(string rawValue)
        {
            if (rawValue == string.Empty || rawValue == Regex)
            {
                return null;
            }
            else
            {
                return new Regex(@"[a-zA-z\s]*").Replace(rawValue, string.Empty);
            }
        }



请让我知道为什么会这样。

提前致谢

Harshal


Please let me know why is this happen .
Thanks in Advance
Harshal

推荐答案

正是因为这行 rawValue == Regex

如果你想匹配你的rawValue匹配Regex表达式你可以这样做

It is because of this line rawValue == Regex
If you want to match your rawValue matches Regex expression you can do it like this
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
  MatchCollection matches = rgx.Matches(input);
  if (matches.Count > 0)
  {
     //code
  }



查看有关 Regex Class


嗯。

正则表达式是一种类型,所以你无法比较带有它的字符串:

Um.
Regex is a type, so you can't compare a string with it:
if (rawValue == string.Empty || rawValue == Regex)
{
    return null;
}

无效。

代替,尝试开始:

Won't work.
instead, try starting with:

if (string.IsNullOrWhiteSpace(rawValue))
{
    return null;
}


这篇关于System.Text.RegularExpressions ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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