[英]vb.net how to get rid of unwanted vblf char
Hi everyone can someone explain to me why he vblf character keeps getting in my string please? 大家好,有人可以向我解释为什么他的vblf角色不断进入我的字符串吗? i use this code so i don't have to check if the http:// already exists in the string with an 'if'
我使用此代码,因此我不必检查字符串中是否已经存在带有“ if”的http://
url1 = "http://" + URL.replace("http://","").Split("/")(0) & strin2
the problem is the result url is like this : "http://" & vblf & 'the rest of the url can anyone explain to me why the vblf keeps getting in my string? 问题是结果url像这样:“ http://”&vblf&'其余的url谁能向我解释为什么vblf不断进入我的字符串中?
I would really use the right tool for the job which seems to be the Uri
class : 我真的会为
Uri
类使用正确的工具来完成这项工作:
Dim url As String = "http://google.com/blah?foo=1"
Dim uri As Uri
If Uri.TryCreate(url, UriKind.Absolute, uri) Then
Dim schemeAndHost As String = uri.Scheme + uri.SchemeDelimiter + uri.Host
End If
Result: http://google.com
结果:
http://google.com
: http://google.com
If you don't know if the url contains the protocol you could use the UriBuilder
class: 如果您不知道网址是否包含协议,则可以使用
UriBuilder
类:
Dim url As String = "google.com/blah?foo=1"
Dim schemeAndHost As String
Dim uri As Uri = Nothing
If uri.TryCreate(url, UriKind.Absolute, uri) Then
schemeAndHost = uri.Scheme + uri.SchemeDelimiter + uri.Host
ElseIf url.Contains("/") Then
uri = New UriBuilder("http", url.Remove(url.IndexOf("/"))).Uri
schemeAndHost = uri.Scheme + uri.SchemeDelimiter + uri.Host
End If
(same result) (结果相同)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.