Java是否有'@'字符来转义字符串引号? [英] Does Java have the '@' character to escape string quotes?

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

问题描述

我的字符串中有双引号,在 C#我会这样做:

My string has double quotes in it, in C# I would do:

string blah = @"this is my ""text";

我如何用Java做到这一点?

how would I do that in Java?

推荐答案

不。这种功能在Java中不可用。

来自Sun的 docs

No. Such a feature is not available in Java.
From the Sun docs:

当在print语句中遇到转义序列时,编译器会相应地解释它。例如,如果要在引号内加上引号,则必须在内部引号上使用转义序列\。要打印句子

When an escape sequence is encountered in a print statement, the compiler interprets it accordingly. For example, if you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes. To print the sentence

She said "Hello!" to me.

你会写吗

System.out.println("She said \"Hello!\" to me.");

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

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