Java String使用不带转义字符的引号 [英] Java String use quotes without escape character

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

问题描述

我知道可以通过在它们之前添加 \ 符号来在Java字符串中编写双引号。但是如果在字符串中大量使用双引号,是否有一种方法可以将字符串标记一次,因此不需要在之前编写 \ 符号每? (就像在C#中一样,可以在字符串前加上 @ 符号)
示例:

I know that it is possible to write double quotes in Java strings by putting \ symbol before them. But if double quotes are used a lot in a string, is there a way to mark the string once, so there won't be a need to write the \ symbol before each? (just like in C#, it is possible to put the @ symbol before the string) Example:

String quotes = @"""""""""""""""""""";

而不是

String quotes = "\"\"\"\"\"\"\"\"\"\"\"";


推荐答案

你不能。但是如果你懒得逃脱每一双引用,有一些技巧可以做到这一点。例如:

You can't. But if you are too lazy to escape each of the double quotes, there are some trick that can do that. For example:

String quotes = "....................".replace(".","\"");
System.out.println(quotes);

输出:

这篇关于Java String使用不带转义字符的引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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