I'm looking for ways to convert text with spaces and symbols in html in android,
For Example:
"Hi this is my text" to "Hi%20this%20is%20my%20text"
Also with symbols...
Anyone knows any easy way to do it?
What I find is to convert html text to plain text.
Thanks in Advance......
What you need is not HTML but URL encoding, use URLEncoder.encode, see http://developer.android.com/reference/java/net/URLEncoder.html
For example, if your write
String s = URLEncoder.encode("Hi this is my text", "UTF-8");
variable s will contain Hi%20this%20is%20my%20text
Use TextUtils.htmlEncode() for this purpose.
Related
I'm having an issue when using the EvaluteJavascript on both Android and iOS (I'm using Xamarin).
The issue is when I want to pass a string argument to a javascript function, if that string contains special character, the js compiler will not understand.
For example:
EvaluateJavascript("updateHtml('Some Html \n Some Html')")
But if i use, this will work:
EvaluateJavascript("updateHtml('Some Html Some Html')")
So the question is how am i able to pass entire string as argument to the javascript function in EvaluateJavascript.
Thanks in advance :)
I was able to solve my issue.
I encoded my string as URL encoding like this
EvaluateJavascript('$"updateHtml({Uri.EscapeUriString("Some Html \n Some Html"'})))
Then in my javascript i just need to decode it by using:
document.getElementById("body").innerHTML = decodeURI(html);
How about using "\\n" instead of "\n" ?
Android Html.fromHtml function auto converts undesired text into hyperlinks.
Here is my code:
String htmlContent= "corners of nail.It has to";
textViewContent.setTextHtml.fromHtml(htmlContent));
textViewContent.setText(comment.getContent());
In above code Html.fromHtml treats "nails.It" as a link and converts it into hyperlink.
Here is the result of converted string.
One of the solution which I could think is, put space after fullstop.
Is there any good solution?
You can try something like this.
textViewContent.setText( Html.fromHtml("YOUR DESIRED TEXT"));
textViewContent. setMovementMethod(LinkMovementMethod.getInstance());
Hope it helps.
Provide space between dot and second statement
String htmlContent= "corners of nail. It has to";
textViewContent.setTextHtml.fromHtml(htmlContent));
textViewContent.setText(comment.getContent());
I am getting some strings from json. My string contains special characters like "æ" from Næstved an many more like "ø" from køkken. But When I set Text these strings to ant textview, I get my strings printed in unusual way.
Example: For køkken I get kø ;kken.
I think I need to encode or decode my string somewhere but where I don,t know.
Please help.
Thanks in advance
The displayed version of your string represents an HTML encoded entity. You might want to verify that it is not coming in this way in your JSON data, but in any case, to decode it you can use the StringEscapeUtils.unescapeHtml4 method from Apache Commons Lang:
final String escaped = "køkken";
System.out.println(StringEscapeUtils.unescapeHtml4(escaped));
Output:
køkken
Did you check out the Latin Coding for your characters? I know the Ash character can be coded with æ and will show up æ in the browser.
Here is the a list of codes
Hope this helps!
My data in db is stored in html format along with image tags in it. So when I am getting the data from database I am removing the html tags and setting it to textview. My problem is even after removing the html tags, there is a small square box displaying in the emulator indicating that there is some image. How can I remove those square box in emulator which is an indication of image in that html data? Help me regarding this...
Thanks in advance
My Code:
textView.setText(Html.fromHtml(htmlString));
You could do a regex replace <img.+?> on htmlString.
textView.setText(Html.fromHtml(htmlString.replaceAll("<img.+?>", "")));
Untested
since images can look like:
<img ...></img>
and
<img... />
This solution will match both cases:
String htmlBody = htmlString.replaceAll("<img.+/(img)*>", "");
textView.setText(Html.fromHtml(htmlBody));
None of the answers are able to remove all possible img tags.
The most appropriate answer would be
String htmlBody = htmlString.replaceAll("(<(/)img>)|(<img.+?>)", "");
It will remove and tags both. And not remove any content between two images.
hi have a look on this example
String temp="<img>helloo</img><b> this is test</b>";
temp= temp.replace("<img>", "");
temp= temp.replace("</img>", "");
textView.setText(Html.fromHtml(temp));
String = " This is SAMPLE"
I want to increase the size of the SAMPLE alone in String to highlight, but need to be in a single string, this is to set in TextView.
Thanks in Advance.
textView.setText(Html.fromHtml("This is <font color='#707070' size='20'>
SAMPLE</font>"));
Try this:
String str = "This is <b>SAMPLE</b>";
yourTextView.setText(Html.fromHtml(str), BufferType.SPANNABLE);
Moreover, you may decorate your string (str) with html tags to alter the looks.
Or to highlight a part of text without using html stuff, read this
Use Html.fromHtml() in setText() of TextView. Supported Html Tags can be found here Html Tags Supported by TextView
I think this is possible if you pass the text as html with your highlighted part enclosed in html <bold> tag.
You have two options:
1, Format your string in HTML and use HTML.from("Your text");
2, Use spannable. A complete guide can find link here