简体   繁体   English

如何逃避成为字符串一部分的斜杠?

[英]How to escape slashes that are to be part of the string?

Im having difficulty finding a way to escape these quotes, 我很难找到逃避这些报价的方法,

String key = StringUtils.substringBetween(html, "class=\"category_keyword\"", ">");

Specifically this part: 特别是这部分:

"class=\\"category_keyword\\""

How the heck do I escape the quotes in ( \\"category_keyword\\" ) while keeping the slashes? 我是如何在保留斜线的同时逃避( \\“category_keyword \\” )中的引号?

Those slashes are not for escaping they are part of the string. 这些斜杠不是为了逃避它们是字符串的一部分。 Yet when i add another (to escape the quote), Eclipse thinks I'm escaping the slash next to it. 然而,当我添加另一个(为了逃避引用)时,Eclipse认为我正在逃避它旁边的斜杠。

Im sorry if this is a bit confusing, let me know if i could be more clear. 对不起如果这有点令人困惑,请告诉我是否可以更清楚。

You can simply do: \\\\\\"category_keyword\\\\\\" 你可以简单地做: \\\\\\"category_keyword\\\\\\"

\\\\ => You are escaping the slash \\ \\\\ =>您正在逃避斜线\\

\\" => You are escaping the quote " \\" =>你正在逃避报价"

public class Class{
    public static void main(String[] a){
        System.out.println(" \\\"Ferrari\\\" ");
    }
}

如果你想保留斜线但是要转义引号:

\\\"category_keyword\\\"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM