获取字符串中两个字符串之间的字符串 [英] Get string between two strings in a string
本文介绍了获取字符串中两个字符串之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串:
"super exemple of string key : text I want to keep - end of my string"
我只想保留 "key : "
和 " - "
之间的字符串.我怎样才能做到这一点?我必须使用正则表达式还是可以用其他方式来做?
I want to just keep the string which is between "key : "
and " - "
. How can I do that? Must I use a Regex or can I do it in another way?
推荐答案
也许,一个好方法就是剪掉一个子串:
Perhaps, a good way is just to cut out a substring:
String St = "super exemple of string key : text I want to keep - end of my string";
int pFrom = St.IndexOf("key : ") + "key : ".Length;
int pTo = St.LastIndexOf(" - ");
String result = St.Substring(pFrom, pTo - pFrom);
这篇关于获取字符串中两个字符串之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文