简体   繁体   中英

What should be the VB.NET equivalent of below C# code?

//Insert new url in the image tag
src = "src=\"" + context.Request.Url.Scheme + "://" + context.Request.Url.Authority + src + "\"";

Receiving Syntax error at "://" while converting from C# to to VB.NET.

As @Olvarsham's answer puts, VB escapes double-quotes by doubling them.

However I feel it would be cleaner to rewrite the expression as a format-string:

src = String.Format("src=""{0}://{1}{2}""", context.Request.Url.Scheme, context.Request.Url.Authority, src)

If you reference context.Request.Url above, it gets simpler:

Dim url As Url = context.Request.Url
src = String.Format("src=""{0}://{1}{2}""", url.Scheme, url.Authority, src)

VB.NET的转义序列是通过将双引号加倍来实现的。

src = "src=""" + context.Request.Url.Scheme + "://" + context.Request.Url.Authority + src + "\"""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM