检索特定的模式内在价值 [英] retrieve value inside certain pattern
本文介绍了检索特定的模式内在价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个图案,像这样
世界是#光亮#和#美丽的#
我需要检索字符串亮,美丽## ..里面的指针
我的解决方案(感谢跑路):
字符串s =世界是光明##和##美丽;
的String []海峡= s.Split('#');
的for(int i = 0; I< = str.Length - 1;我++)
{
如果(I%2!= 0)
{
的Response.Write(STR [I] +< BR />中);
}
}
解决方案
如果你想要的是里面的##串,则不需要正则表达式,只需使用string.Split:
字符串rawstring =世界是光明##和美丽的;
的String [] = TEM rawstring.Split('#');
在这之后,你需要的是得到偶数项(索引:1,3,5 ....)从的String []统
i have a pattern as like this
"The world is #bright# and #beautiful#"
i need to retrieve the string "bright","beautiful" inside # # .. any pointers
My solution (thanks to Bolu):
string s = "The world is #bright# and #beautiful#";
string[] str = s.Split('#');
for (int i = 0; i <= str.Length - 1; i++)
{
if (i % 2 != 0)
{
Response.Write(str[i] + "<br />");
}
}
解决方案
If all you want is the string inside ##, then no need for regex, just use string.Split:
string rawstring="The world is #bright# and beautiful";
string[] tem=rawstring.Split('#');
After that, all you need is to get the even item (with index: 1,3,5....) from the string[] tem
这篇关于检索特定的模式内在价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文