Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flip a letter upside down?

Here I'm trying to flip an English letter upside down for my mail template.

Well I can get it manually. What I'm doing is now manually

just like

 content.append("ɥ"); //actual h letter.
 content.append("ǝ")// actual e letter.

So my question is that , is there any trick/method/any clue to do it in programmatic way ?

What I'm doing now is

switch(letter) {

case 'e':
   return 'ǝ';
}

That looks odd and looking for hints. Thanks for any help.

like image 896
Suresh Atta Avatar asked Jun 23 '14 17:06

Suresh Atta


2 Answers

I'm not sure of a java-specific solution, but seeing as Strings in java use unicode, I checked out the unicode characters for their upside down counterparts here: http://www.fileformat.info/convert/text/upside-down-map.htm

It doesn't look there's a good programmatic method for finding these. However, there are a variety of converters, like this one http://www.fileformat.info/convert/text/upside-down.htm You could generate config files based on input and output of one of these types of converters and use those config files to drive your upside-down letter selection

like image 122
Jacob Bartel Avatar answered Sep 18 '22 02:09

Jacob Bartel


The fastest way to do character replacement is an array.

create an array of upside down letters. Then, do a check of the value coming in and find it's match.

Java allows you to get the integer representation of a character by simply casting int x = char a; So, it stands to reason that your upsidedown a would be at the index of your char minus the lowest char you are mapping (usually lowercase a).

char[] updown = {'ɐ','q','ɔ','p','ə','ɟ','ƃ','ɥ','ı','ɾ','ʞ','l','ɯ','u','o','d','b','ɹ','s','ʇ','n','ʌ','ʍ','x','ʎ','z'};
//this example uses 26 chars, all lower case;
int a = 'a';
int z = 'z';

String newString = "";
for(int i=0; i<string.length; i++){
    int ch = string.charAt(i);
    if(ch>= a && ch <=z){
        newString = (updown[ch-a]) + newString;
    }
}

Here's a link to IDEONE where you can compile and test for yourself. http://ideone.com/LombFE

like image 28
Adam Yost Avatar answered Sep 19 '22 02:09

Adam Yost