如何在字符串中写双引号? [英] How to write double quotes in string?

查看:98
本文介绍了如何在字符串中写双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着在cmd中写这样:

C:\Program Files \WinRAR\Rar.exea C:\ Users \ User &\\Desktop \\ \\ temp.zipC:\ Users\User \Desktop\img

但使用此代码:

I tried to write in cmd this as is:
"C:\Program Files\WinRAR\Rar.exe" a C:\Users\User\Desktop\temp.zip "C:\Users\User\Desktop\img"
but using this code:

Console( '"' + path_to_winrar + '"' +  " a " + dest + " " + '"' +source +'"');



我得到了

\C:\\Program Files \\WinRAR \\Rar.exe \ 一个C:\\Users \\User \\Desktop \\ 18.12.2012.zip \C:\\Users\\User \\Desktop \ \\ img \\\

如何?


I got
"\"C:\\Program Files\\WinRAR\\Rar.exe\" a C:\\Users\\User\\Desktop\\18.12.2012.zip \"C:\\Users\\User\\Desktop\\img\\\""
How?

推荐答案

您可以使用\或者如果你放一个@在字符串的前面,使用。



,如字符串s = @这是在引号,好吗? ;
You can use \" or if you put a @ at the front of the string, use "".

as in string s = @"this is in ""quotes"", OK ? ";


字符串是正确的,但是您已经被插入转义字符的调试器显示混淆了。



转储你的字符串到控制台,你会发现它没问题。



尝试

The string is correct but you have been confused by the debugger display which inserts escape characters.

Dump your string to the console and you''ll see that it''s ok.

Try
string s = '"' + "hello" + '"' + " " + '"' + "!" + '"';
Console.WriteLine(s);





控制台将显示

你好!



和调试器wi ll show

\hello \\!\



Alan。



The Console will show
"hello" "!"

and the debugger will show
"\"hello\" \"!\""

Alan.




试试这个,

Hi,
Try this,
string path_to_winrar = @"C:\Program Files\WinRAR\Rar.exe";
string dest = @"C:\Users\User\Desktop\temp.zip";
string source = @"C:\Users\User\Desktop\img";
string result = string.Format("\"{0}\" a {1} \"{2}\"", path_to_winrar, dest, source);





我希望这会有所帮助。

谢谢:)



I hope this will help.
Thanks :)


这篇关于如何在字符串中写双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆