我尝试在我的方法中使用C#中的正则表达式匹配。但它不起作用 [英] I try to use regex match in C# in my method. But it's not working

查看:79
本文介绍了我尝试在我的方法中使用C#中的正则表达式匹配。但它不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作循环并且我想匹配$符号之后的所有内容,例如我有:

$ TWTR所以,我想匹配TWTR所以除了数字之外的所有内容0 -9\" 。



我尝试过这样的事情:



I made loop for and I'd like to match everything after "$" symbol for example I have:
$TWTR so, I want to match "TWTR" so everything beside numbers "0-9".

I tried something like this:

var regexp = new Regex(@"s!(\w+)");
var matches = regexp.Matches(df);





但它返回null。



我尝试过:





But it's returned null.

What I have tried:

<pre lang="c#">

     public void CheckSymbol(StockCollection el)
        {
            for (int i = el.Stockdata.Count - 1; i >= 0; i--)
            {
                char s = '$';
                string Symbl = String.Concat(s, ticker);



                string text = el.Stockdata[i].Body;
                bool value = text.Contains(Symbl);


                if (value == true)
                {
                    var df = text.Replace(Symbl, "*****");
                    bool value2 = df.Contains(s);


                    //string str = ...;
                //    bool isLetter = !String.IsNullOrEmpty(str) && Char.IsLetter(str[0]);

                    if (value2 == true ) 
                    {
                        el.Stockdata.RemoveAt(i);
                    }
                    else
                    {
                        df.Replace("*****", Symbl);
                    }
                }
            }

推荐答案

符号例如我有:
" symbol for example I have:


TWTR所以,我想匹配TWTR所以除了数字0-9旁边的所有内容。



我尝试了一些东西像这样:



TWTR so, I want to match "TWTR" so everything beside numbers "0-9".

I tried something like this:

var regexp = new Regex(@"s!(\w+)");
var matches = regexp.Matches(df);





但它返回null。



我尝试过:





But it's returned null.

What I have tried:

<pre lang="c#">

     public void CheckSymbol(StockCollection el)
        {
            for (int i = el.Stockdata.Count - 1; i >= 0; i--)
            {
                char s = '


';
string Symbl = String.Concat(s,ticker);



string text = el.Stockdata [i] .Body;
bool value = text.Contains(Symbl);


if(value == true)
{
var df = text.Replace(Symbl,*****);
bool value2 = df.Contains(s);


// string str = ...;
// bool isLetter =!String.IsNullOrEmpty(str)&& Char.IsLetter(STR [0]);

if(value2 == true)
{
el.Stockdata.RemoveAt(i);
}
其他
{
df.Replace(*****,Symbl);
}
}
}
'; string Symbl = String.Concat(s, ticker); string text = el.Stockdata[i].Body; bool value = text.Contains(Symbl); if (value == true) { var df = text.Replace(Symbl, "*****"); bool value2 = df.Contains(s); //string str = ...; // bool isLetter = !String.IsNullOrEmpty(str) && Char.IsLetter(str[0]); if (value2 == true ) { el.Stockdata.RemoveAt(i); } else { df.Replace("*****", Symbl); } } }


这篇关于我尝试在我的方法中使用C#中的正则表达式匹配。但它不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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