Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape string from EditText

I was just wondering, if I have an EditText that I'm turning the content of into a string, say

String queryStr = new String(searchText.getText().toString());

How would I go about escaping special characters from this string so that I could put it into an HttpGet method? Thanks!

like image 571
Nick Avatar asked Nov 11 '10 17:11

Nick


2 Answers

Use java.net.URLEncoder:

java.net.URLEncoder.encode(queryStr, "UTF-8");
like image 196
Peter Knego Avatar answered Oct 18 '22 05:10

Peter Knego


Try:

TextUtils.htmlEncode(queryStr);

I think that should do what you want.

like image 25
Kevin Coppock Avatar answered Oct 18 '22 06:10

Kevin Coppock