2011-11-28 80 views
0

我需要這個字符串轉換爲我的VB適當的形式,網絡代碼字符串轉義轉換vb.net

if (c == '"') { 
s.Append('"'); 
} else if (c == '\\') { 
s.Append('\\'); 
} else if (c == '/') { 
s.Append('/'); 
} else if (c == 'b') { 
s.Append('\b'); 
} else if (c == 'f') { 
s.Append('\f'); 
} else if (c == 'n') { 
s.Append('\n'); 
} else if (c == 'r') { 
s.Append('\r'); 
} else if (c == 't') { 
s.Append('\t'); 
} else if (c == 'u') { 

這是不恰當地轉換到

If c = """"c Then 
    s.Append(""""c) 
ElseIf c = "\"c Then 
    s.Append("\"c) 
ElseIf c = "/"c Then 
    s.Append("/"c) 
ElseIf c = "b"c Then 
    s.Append(ControlChars.Back) 
ElseIf c = "f"c Then 
    s.Append(ControlChars.FormFeed) 
ElseIf c = "n"c Then 
    s.Append(ControlChars.Lf) 
ElseIf c = "r"c Then 
    s.Append(ControlChars.Cr) 
ElseIf c = "t"c Then 
    s.Append(ControlChars.Tab) 
ElseIf c = "u"c Then 

有人可以幫我做正確的字符串轉義碼

感謝

編輯

thansk所有的人幫助我,到目前爲止,但主要的問題是

你怎麼引用這樣'"'在VB中,因爲我不能在這裏

+0

你是如何進行轉換的? –

+0

這可能不是主題,但是你是否有充分的理由去做'。附加(c)'17行? – Otiel

+0

這看起來很安靜。你從哪裏得到這個字符串?你可以使用正則表達式來解決這個問題嗎?請告訴我們,必須更換字符,以及如何加載字符串。 – oberfreak

回答

1

使用單引號的轉換代碼是正確的。你可以使用ChrW(34),如果這讓你感覺更舒服:

If c = ChrW(34) Then 
     s.Append(ChrW(34)) 
    '' etc... 
+0

轉換後的代碼不正確,並且不會將期望的輸出作爲c#版本。 – Smith