Created
February 10, 2012 16:45
-
-
Save anonymous/1790754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param word String to be turned into T9 code | |
* @return the T9 code of the input string | |
* | |
* Method returns the order of buttons of digipad buttons to be pressed to | |
* get the input String from a T9 predictive text dictionary. | |
* | |
* This method assumes the order of the buttons is as follows and ignores case: | |
* | |
* 2= a,b,c | |
* 3= d,e,f | |
* 4= g,h,i | |
* 5= j,k,l | |
* 6= m,n,o | |
* 7= p,q,r,s | |
* 8= t,u,v | |
* 9= w,x,y,z | |
* | |
* punctuation of any kind is replaced with a " ". | |
* | |
*/ | |
public static String wordToSignature(String word){ | |
String code = ""; | |
while(!(word=="")){ //while the word isn't empty | |
String l = word.substring(0, 1); //first letter of the word | |
if(l.equalsIgnoreCase("a")||l.equalsIgnoreCase("b")||l.equalsIgnoreCase("c")){ | |
code +="2"; | |
}else if(l.equalsIgnoreCase("d")||l.equalsIgnoreCase("e")||l.equalsIgnoreCase("f")){ | |
code +="3"; | |
}else if(l.equalsIgnoreCase("g")||l.equalsIgnoreCase("h")||l.equalsIgnoreCase("i")){ | |
code +="4"; | |
}else if(l.equalsIgnoreCase("j")||l.equalsIgnoreCase("k")||l.equalsIgnoreCase("l")){ | |
code +="5"; | |
}else if(l.equalsIgnoreCase("m")||l.equalsIgnoreCase("n")||l.equalsIgnoreCase("o")){ | |
code +="6"; | |
}else if(l.equalsIgnoreCase("p")||l.equalsIgnoreCase("q")||l.equalsIgnoreCase("r")||l.equalsIgnoreCase("s")){ | |
code +="7"; | |
}else if(l.equalsIgnoreCase("t")||l.equalsIgnoreCase("u")||l.equalsIgnoreCase("v")){ | |
code +="8"; | |
}else if(l.equalsIgnoreCase("w")||l.equalsIgnoreCase("x")||l.equalsIgnoreCase("y")||l.equalsIgnoreCase("z")){ | |
code +="9"; | |
}else{ | |
code +=" "; | |
} | |
if(word.length()>1){ | |
word=word.substring(1,word.length()); //returns the word minus its first letter | |
}else{ | |
break; // prevent outofbounds exception | |
} | |
} | |
return code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment