如何访问正则表达式语句中的变量?时间:2019-04-14 标签:c#4.0
我已经到处寻找,但我一生都无法弄清楚如何使正则表达式语句中的变量可以从其他地方访问。
如果有人能提供帮助那就太棒了! 这是代码:
string strRegex = @"(regexstring)";
RegexOptions myRegexOptions = RegexOptions.Multiline;
Regex myRegex = new Regex(strRegex, myRegexOptions);
string strTargetString = str9
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
这是问题 --> 。 。 ...................... 字符串 str5 = myMatch.ToString();
}
webBrowser1.navigate(str5); <-- 这不起作用
如何访问字符串 str5?在循环之外?请帮忙
I have looked everywhere, but I cannot for the life of me figure out how to make a variable inside a regex statement be accessible from elsewhere.
If someone could help that would be amazing!
Here is the code:
string strRegex = @"(regexstring)";
RegexOptions myRegexOptions = RegexOptions.Multiline;
Regex myRegex = new Regex(strRegex, myRegexOptions);
string strTargetString = str9
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
Here is the problem --> . . ..................
string str5 = myMatch.ToString();
}
webBrowser1.navigate(str5); <-- This doesnt work
How Do I access the string str5? outside of the loop? Please Help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想在循环外部访问变量,则需要在循环外部声明该变量。但是,您随后需要考虑:
您需要在循环外为其分配一个变量,否则当您尝试读取该变量时,编译器会抱怨,因为它没有明确分配。
If you want to access the variable outside the loop, it needs to be declared outside the loop. However, you then need to consider:
You'll need to assign a variable to it outside the loop as otherwise when you try to read the variable, the compiler will complain because it's not definitely assigned.
也许你想要:
Perhaps you want: