字符串内的引号 [英] Quotation marks inside a string

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

问题描述

我需要你们的帮助。我有一个字符串 name =john

I need some help from you guys. I have a string name = "john"

但我想将此字符串名称保存为john,包括(报价)

But I want to save this String name as "john", including ""(quotations)

String name = ""john"";
String name1 = "[john]"

有人可以帮我解决这个问题。

Can some one help me with this.

推荐答案

String name = "\"john\"";

您必须使用前面的\字符转义第二对引号。可能值得一看 http://www.javacoffeebreak.com/faq/faq0050.html详细解释。

You have to escape the second pair of quotation marks using the \ character in front. It might be worth looking at http://www.javacoffeebreak.com/faq/faq0050.html which explains in some detail.

您设置变量的其他方案:

Other scenario where you set variable:

String name2 = "\""+name+"\"";

控制台中的序列:

> String name = "\"john\"";
> name
""john""
> String name2 = "\""+name+"\"";
> name2
"""john"""

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

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