从字符串中检索数据 [英] Retrieve data from a string
本文介绍了从字符串中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有这样的字符串:
Hi all
I have a string like this:
string abc = " /*some 10 lines of code */
// Program Begin
{
//Some Code Here
//Some Code Here
//Some Code Here
//Some Code Here
//Some Code Here
}
// Program End
//some liens of code
//some liens of code";
我只需要"//程序开始"和"//程序结束"之间的代码.
怎么做.
我在Google中搜索,但未得到任何有效结果.
请帮助
预先感谢.
I want only the code between "// Program Begin" and "// Program End".
How to do this.
I searched in Google and not get any effective result.
Please Help
Thanks in advance.
推荐答案
您可以使用System.String.IndexOf("//Program Begin")和
System.String.IndexOf("//程序结束")
在此处详细说明 [此处详细说明 [
You can find the index of your start element and end element by using System.String.IndexOf("// Program Begin") and
System.String.IndexOf("// Program End")
details here[^]
Then you can do a System.String.Substring(firstIndex, numberOfcharacters)
details here[^]
The numberOfCharacters can be retrieved by subtracting both indexes in the right order.
Good luck!
这篇关于从字符串中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文