vb.net 剪切字符串直到出现特定字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19583745/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:36:57  来源:igfitidea点击:

Cutting a string Until a particular character occurs

vb.netstring

提问by Mirage

whats the code to cut or trim a string until a particular character is hit.

剪切或修剪字符串直到命中特定字符的代码是什么。

for example,

例如,

dim TestString as String = "REG - REGULAR"

output of this string after cutting should be,

切割后这个字符串的输出应该是,

"REG" 

The code should be able to cut the string until it reaches this character "-".

代码应该能够剪切字符串直到它到达这个字符“-”。

It should also remove the white spaces. whats the code for doing this task.

它还应该删除空格。执行此任务的代码是什么。

I am using vb.net.

我正在使用 vb.net。

Thank You

谢谢你

回答by Tilak

You can use String.Substring

您可以使用String.Substring

TestString = TestString.Substring(0,TestString.IndexOf('-')).Trim()