vb.net 子字符串并返回特定字符后的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11130658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
substring and return the value after a specific character
提问by Fire Hand
"Testing.BSMain, Text: Start Page"
“Testing.BSMain,文本:起始页”
I would like to substring the value above and returning me only the value after the ": "in vb.net. How can i do that?
我想对上面的值进行子字符串化,并只返回vb.net 中“:”之后的值。我怎样才能做到这一点?
回答by LarsTech
Assumes no error checking:
假设没有错误检查:
Dim phrase As String = "Testing.BSMain, Text: Start Page".Split(":")(1)
which simply splits the phrase by the colon and returns the second part.
它只是用冒号分割短语并返回第二部分。
To use SubString, try this:
要使用 SubString,试试这个:
Dim test As String = "Testing.BSMain, Text: Start Page"
Dim phrase As String = test.Substring(test.IndexOf(":"c) + 1)
回答by Nudier Mena
you can use the split method to return the value after the colon :
您可以使用 split 方法返回冒号后的值:
Dim word as String = "Testing.BSMain, Text: Start Page"
Dim wordArr as String() = word.Split(":")
Dim result as String = wordArr(1);