字符串转义转换vb.net

时间:2011-11-28 21:55:51

标签: c# .net vb.net escaping

我需要将此字符串转换为我的vb中的正确格式,网络代码

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

有人可以帮我做正确的字符串转义码

感谢

修改

到目前为止,向所有帮助我的人提供了解决方案,但主要问题是

你如何在vb中引用这个'"',因为我不能在这里使用单引号

1 个答案:

答案 0 :(得分:1)

转换后的代码是正确的。你可以使用ChrW(34),如果这让你感觉更舒服:

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