vb.net 在某个字符后读取字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18323299/
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
vb.net read string after certain character
提问by user2618553
I have an listbox which has some random URLs + basic info, eg:
我有一个列表框,其中包含一些随机 URL + 基本信息,例如:
[search website] - http://www.google.com/
[games website] - http://www.miniclip.com/
Each line is an item.
每一行都是一个项目。
When I try to use this code, it crashes:
当我尝试使用此代码时,它崩溃了:
Private Sub doubleclickitem(sender As Object, e As EventArgs) Handles ListBox1.DoubleClick
Dim url As String = ListBox1.SelectedItem
Process.Start(url)
End Sub
The error is the first characters are unknown for Process.Start.
错误是the first characters are unknown for Process.Start。
How can I start the url? Someone told me I have to read the lines after the first " - ". Is this right? If so, how can I do so?
我怎样才能开始网址?有人告诉我必须阅读第一个“ - ”之后的行。这是正确的吗?如果是这样,我该怎么做?
采纳答案by Magnus
This should do it:
这应该这样做:
url = url.Substring(url.LastIndexOf(" - ") + 3)
回答by user2366842
you should be assigning a value to each text item in the list, then retrieving the value, and feeding that to process.start, for example if you want process.start to open google, then it would be like so....(provided you assign a value of http://www.google.comto whatever the selected item is)
您应该为列表中的每个文本项分配一个值,然后检索该值,并将其提供给 process.start,例如,如果您希望 process.start 打开 google,那么它会是这样....(如果您将http://www.google.com的值分配给所选项目的任何内容)
Process.Start(ListBox1.SelectedValue)
this is for c#, but the same ideals will still apply http://forums.asp.net/t/1199141.aspx/1
这是针对 c# 的,但同样的理想仍然适用http://forums.asp.net/t/1199141.aspx/1
回答by Abdisamad Khalif
Try this:
尝试这个:
YourTextBox.Text = YourString.Substring(0, YourString.Text.LastIndexOf(" - "))

