This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Converting characters to symbols/emoticons

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,


I am stuck with an issue,i am fetching feeds from different social networking sites and displaying them somewhere while doing this few characters like <3 is converted to a heart symbol there are many other characters like smileys etc, so just wanna know what would be the best approach to handle these conversions in JAVA.





-Regards,
Rohit Sharma
 
Marshal
Posts: 74371
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There probably is not a “best” way to do these things. You realise there are Unicode characters for smileys? This, for example, is \u263b: ☻ There are replacement methods in the String class. Have you tried them?
 
Rohit Shaarma
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah we can replace string with unicode character but that looks good if we are dealing with a single symbol/emoticon but how should be the design if we want to take care of multiple symbols/emoticons.
would just having a map of all the spl symbols and then checking for their presence in the messages and then replacing them would do??
 
Campbell Ritchie
Marshal
Posts: 74371
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does “spl” mean? Please read this.

You can put the symbols and their ASCII translations in a Map (as “V” and “K” respectively), yes. You might find you have to traverse the String and seek whether the String begins with all the “K”s at each character. Then you can append the character to a StringBuilder. Yes, it would work, but you are going to find that runs in O(m × n) complexity, which is rather like quadratic complexity.
You might not find a solution which has a lower complexity.
 
Rohit Shaarma
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Currently have implemented using javascript replace function by replacing the special characters with unicode characters, its working great just wondering whether handling on UI side is appropriate or not.
 
lowercase baba
Posts: 13014
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:What does “spl” mean?

"Spleen" is the only thing I can think of...
 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rohit Shaarma wrote:Currently have implemented using javascript replace function by replacing the special characters with unicode characters



And you could have done that exactly the same way in Java. I guess that answers your original question then.

its working great just wondering whether handling on UI side is appropriate or not.



That entirely depends on the details of your application.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic