vb.net 拆分字符串的最后一部分

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

vb.net split last part of the string

vb.netstringsplit

提问by Timothy Staudt

net 2.0 and need to split the last / mark of the string. Currently I have a code that says Dim test As String = "Software\Microsoft\Windows\Welcome"and need a code that will split that Software\Microsoft\Windows\Welcome into two separate section at the end So I'll have Software\Microsoft\Windows and Welcome as new strings. I can only find things that will split the beginning from the rest like

net 2.0 并且需要拆分字符串的最后一个 / 标记。目前我有一个代码,Dim test As String = "Software\Microsoft\Windows\Welcome"需要一个代码,将 Software\Microsoft\Windows\Welcome 拆分为两个单独的部分,所以我将 Software\Microsoft\Windows 和 Welcome 作为新字符串。我只能找到将开始与其余部分分开的东西,例如

Dim whole As String = "Software/Microsoft/Windows/Run"
Dim firstpart As String = whole.Substring(0, whole.IndexOf("/"))
Dim lastpart As String = whole.Substring(whole.IndexOf("/") + 1)`

回答by shf301

Use String.LastIndexOf()

使用String.LastIndexOf()

Dim whole As String = "Software/Microsoft/Windows/Run"
Dim firstpart As String = whole.Substring(0, whole.LastIndexOf("/"))
Dim lastpart As String = whole.Substring(whole.LastIndexOf("/") + 1)

回答by urbanspr1nter

Try splitting with '\' As your delimeter and store it as a string array. Then just grab the last element and it should be "Welcome".

尝试使用 '\' 作为分隔符进行拆分并将其存储为字符串数组。然后抓住最后一个元素,它应该是“欢迎”。