Re: SMS Textspeak Corrector
Hello SHENGTON,
Welcome to the Java Programming Forums.
I don't have any experience in JavaME but in JaveSE you could use the String replaceAll method for correcting - String (Java Platform SE 6)
Re: SMS Textspeak Corrector
Here is an example for you. It's not perfect but you get the idea. Obviousally it needs to be adapted for JavaME.
Code Java:
public static String[] txtWord = {"txt","spk","lol","np","brb"};
public static String[] realWord = {"text","speak","laugh out loud","no problem","be right back"};
public static void main(String[] args) {
String phrase = "Hello mate. Long time no spk, lol. Thats np, i'll brb!";
for(int a = 0; a < txtWord.length; a++){
if(phrase.contains(txtWord[a])){
phrase = phrase.replaceAll(txtWord[a], realWord[a]);
}
}
System.out.println(phrase);
}
Input:
Hello mate. Long time no spk, lol. Thats np, i'll brb!
Output:
Hello mate. Long time no speak, laugh out loud. Thats no problem, i'll be right back!
Re: SMS Textspeak Corrector
Hello JavaPF, good afternoon. :)
Thanks for taking time replying my problem. Thanks for the codes, it gives me an idea how to figure it out. I'll try that later but for now I'm trying to solve how to create submenu in J2ME. I tried to Google it but none of the links gives me an answer.
By they way, I'm using a Motorola cellphone for testing purposes.
Thanks :).
Re: SMS Textspeak Corrector
Hello JavaPF, good evening. :)
Please take a look my code. I having a problem in replacing the text inside the TextBox.
Here's the code:
Code Java:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Command;
public class TextBoxMIDlet extends MIDlet implements CommandListener
{
private Display display;
private static String[] txtWord = {"txt","spk","lol","np","brb"};
private static String[] realWord = {"text","speak","laugh out loud","no problem","be right back"};
private Command txtspk = new Command("Correct Textspeak", Command.ITEM, 0);
private Command exit = new Command("Exit", Command.EXIT, 0);
private TextBox t;
public TextBoxMIDlet() {
display = Display.getDisplay(this);
}
public void startApp() {
t = new TextBox ("TextBox Example", null, 256, TextField.ANY);
t.addCommand(txtspk);
t.addCommand(exit);
t.setCommandListener(this);
display.setCurrent(t);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional){}
public void commandAction(Command command, Displayable displayable)
{
if (command == exit)
{
destroyApp(true);
notifyDestroyed();
}
if (command == txtspk)
{
for(int a = 0; a < txtWord.length; a++)
{
if(t.equals(txtWord[a]))
{
t = t.replaceAll(txtWord[a], realWord[a]);
}
}
System.out.println(t);
}
}
}
I'm having a problem with this this part:
Code Java:
if (command == txtspk)
{
for(int a = 0; a < txtWord.length; a++)
{
if(t.equals(txtWord[a]))
{
t = t.replaceAll(txtWord[a], realWord[a]);
}
}
System.out.println(t);
}
I don't know how to figure it out. What's wrong with my code?