得到两个字符串之间字符串中的字符串 [英] Get string between two strings in a string

查看:111
本文介绍了得到两个字符串之间字符串中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的字符串:

I have a string like that :

"super exemple of string key : text I want to keep - end of my string"

我想只要保持这之间的字符串
键: -
我该怎么办呢?
我必须使用正则表达式或我能做到这一点在其他的方式?

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 an other 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屋!

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