我们怎样才能在位置和分离提取字符串的子 [英] How can we extract substring of the string by position and separator

查看:82
本文介绍了我们怎样才能在位置和分离提取字符串的子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何划分子从字符串

How can we divide the substring from the string

像我有字符串

String mainString="///Trade Time///Trade Number///Amount Rs.///";

现在我有其他的字符串

String subString="Amount"

然后,我要提取的子字符串金额卢比。与第二个字符串的帮助下名为的子没有通过任何其他方法,但它应该是通过两个参数,如首先提取是我的索引再多的字符串,第二个是,直到下一个字符串///.

Then I want to extract the substring Amount Rs. with the help of second string named subString not by any other method But it should be extracted through two parameters like first is I have index no of Amount string and second is until the next string ///.

推荐答案

首先得到该字符串的索引:

First get the index of the substring:

int startIndex = mainString.IndexOf(subString);

然后得到以下斜杠的索引:

Then get the index of the following slashes:

int endIndex = mainString.IndexOf("///", startIndex);

然后你就可以得到你想要的子字符串:

Then you can get the substring that you want:

string amountString = mainString.Substring(startIndex, endIndex - startIndex);

这篇关于我们怎样才能在位置和分离提取字符串的子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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