如何在字符串中定义的字符后拾取字符。 [英] How to pickup character after a defined character in string.

查看:95
本文介绍了如何在字符串中定义的字符后拾取字符。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想在定义的角色后拾取角色。



示例:

如果

Url =菜单[0] [0] =新mI(Home,http://aps.abcd.com/details/0,8590, CLI1_DIV152_ETI3140,00.html)



i想要结果= 0,0



如果是

菜单[0] [1] =新mI(Home,http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html)

结果= 0,1









请帮忙我,提前谢谢。

解决方案

看起来您的数据是包含以下行的字符串:

 Url =菜单[0] [0] =新mI(主页,http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html)

菜单[0] [1] =新mI(主页,http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html)



并且您想要提取用于菜单的两个索引值。

0,0和0,1各自y。

按照这个假设:

 List< string> data =  new 列表< string>()
{
Url = Menu [0] [0] = new mI(\Home\,\http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00 .html \)
菜单[0] [1] =新mI(\Home \,\http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html\)
};

Regex indexFinder = new 正则表达式( @ Menu\ [(\d +)\] \s * \ [(\d +)\]);

foreach string datum in data)
{
匹配indexMatch = indexFinder.Match(datum);
if (indexMatch.Success)
{
Console.Writeline(index.Match.Groups [ 1 ]。值+ + index.Match.Groups [ 2 ]。值);
}
}





是的,我可以使用Console.Writeline的格式字符串()但原始请求可能需要将这两个值作为单个字符串用于其他目的。 ;)


Hi,

I want to pickup character after a defined character.

Example :
if
Url = Menu[0][0]=new mI("Home","http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html")

i want Result = 0,0

if it is
Menu[0][1]=new mI("Home","http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html")
Result = 0, 1




Please help me, Thanks in advance.

解决方案

It looks like your data is strings with lines like:

Url = Menu[0][0]=new mI("Home","http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html")
and
Menu[0][1]=new mI("Home","http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html")


and you want to extract the two index values used for Menu.
"0,0" and "0,1" respectively.
Going with that assumption:

List<string> data = new List<string>()
  {
    "Url = Menu[0][0]=new mI(\"Home\",\"http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html\")",
    "Menu[0][1]=new mI(\"Home\",\"http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html\")"
  };

Regex indexFinder = new Regex(@"Menu\[(\d+)\]\s*\[(\d+)\]");

foreach (string datum in data)
{
  Match indexMatch = indexFinder.Match(datum);
  if (indexMatch.Success)
  {
    Console.Writeline(index.Match.Groups[1].Value + "," + index.Match.Groups[2].Value);
  }
}



Yes, I could have used a format string with the Console.Writeline() but the original request might need the two values as a single string for some other purpose. ;)


这篇关于如何在字符串中定义的字符后拾取字符。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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