Reputation: 329
I am uploading the text to server, i just want to upload those string in html format example
input:
Do you know the relation between two eyes...??? They never see each other... BUT
However, when they see a pretty woman, one will blink and another will not...
sendtext = adding_textjoke.getText().toString();
//String htmlString = Html.toHtml(sendtext);
String str = "(?i)\\b((?:https?://|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'\".,<>?«»“”‘’]))";
Pattern patt = Pattern.compile(str);
Matcher matcher = patt.matcher(sendtext);
sendtext = matcher.replaceAll("<a href=\"$1\">$1</a>");
System.out.println(sendtext);
Log.e("sendtext", sendtext);
new AddJokesTask().execute(sendtext);
How to do this in android?
Upvotes: 2
Views: 4855
Reputation: 71
SpannableStringBuilder text = (SpannableStringBuilder) contentView.getText();
String htmlEncodedString = Html.toHtml(text);
Upvotes: 0
Reputation: 1187
You can do it like this
SpannableString contentText = (SpannableString) contentView.getText();
String htmlEncodedString = Html.toHtml(contentText)
Upvotes: 2