我尝试在我的方法中使用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); } } }