从EditText中转义字符串

Nic*_*ick 5 android get escaping http android-edittext

我只是想知道,如果我有一个EditText,我将内容转换为字符串,比方说

String queryStr = new String(searchText.getText().toString());
Run Code Online (Sandbox Code Playgroud)

我如何从这个字符串中转义特殊字符,以便将其放入HttpGet方法?谢谢!

Pet*_*ego 8

使用java.net.URLEncoder:

java.net.URLEncoder.encode(queryStr, "UTF-8");
Run Code Online (Sandbox Code Playgroud)