我有字符串,在中间的某个地方(左和右有不同的长度),我有这个字符序列(左边和右边有一个空格)。
至:
是否可以在此点拆分并返回左边的字符,即给定以下字符串:
下面是一些文本:这里还有一些不同长度的文本
我希望的结果是:
这是一些文本
发布于 2016-07-22 08:44:22
使用IndexOf与Substring相结合
string s = "Here is some text to: and here is some more text of a different length";
int length = s.IndexOf("to:");
if (length > 0)
{
s = s.Substring(0, length);
}发布于 2016-07-22 08:46:12
好吧,如果你知道你有这个词
String s = "Here is some text to: and here is some more text of a different length"
String result = s.Split(new String[] { "to:" })[0];你把课文分成两半,然后取第一部分。
如果您选择的子字符串不在字符串中,result将只包含普通的s -没有更改。
发布于 2016-07-22 08:48:00
使用string.Split更容易
Dim FirstSplit as String()
FirstSplit = Name.Split(",")
fname = FirstSplit(0).Trim()https://stackoverflow.com/questions/38521955
复制相似问题