当前位置: 动力学知识库 > 问答 > 编程问答 >

android - preg_replace equivalent in java

问题描述:

How to convert this code into java code

$response = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $response);

I try this

String jsonStr = "Some Json string";

jsonStr.replaceAll("/[\x00-\x1F\x80-\xFF]/", "");

But it show an error

Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )

网友答案:

You have to escape the backslashes with another backslash like this:

jsonStr.replaceAll("[\\x00-\\x1F\\x80-\\xFF]", "");

Backslashes in strings introduce special characters in Java.

分享给朋友:
您可能感兴趣的文章:
随机阅读: