//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.下面的C#代碼應該是VB.NET的等價物嗎?
//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.下面的C#代碼應該是VB.NET的等價物嗎?
轉義序列在VB.NET
是由雙引號加倍。
src = "src=""" + context.Request.Url.Scheme + "://" + context.Request.Url.Authority + src + "\"""
正如@ Olvarsham的回答所言,VB通過將其加倍而逃脫雙引號。
不過,我覺得這將是清潔重寫表達格式字符串:
src = String.Format("src=""{0}://{1}{2}""", context.Request.Url.Scheme, context.Request.Url.Authority, src)
如果引用context.Request.Url
上面,它會更簡單:
Dim url As Url = context.Request.Url
src = String.Format("src=""{0}://{1}{2}""", url.Scheme, url.Authority, src)
它工作得很好,我意識到原因。儘管我在雙引號中放置了://但是沒有在雙引號中加上「+ context.Request.Url.Scheme +」://「+ context.Request.Url.Authority + src +」\「 – himanshu
實際上最好是:'src =「src =」「」&context.Request.Url.Scheme&「://」&context.Request.Url.Authority&src&「\」「」' – shadow