How to Search, Compare, and Replace text in the TextBox in J2ME?
Hello, good evening. :)
I'm having a hard time with this on how to search and compare the String array to the TextBox, and replace the text in the textbox.
Here's my 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","no prblm","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 message;
public TextBoxMIDlet() {
display = Display.getDisplay(this);
}
public void startApp() {
message = new TextBox ("TextBox Example", null, 256, TextField.ANY);
message.addCommand(txtspk);
message.addCommand(exit);
message.setCommandListener(this);
display.setCurrent(message);
}
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(message.getString().equalsIgnoreCase(realWord[a]))
{
message = message.setString(realWord[a]);
}
}
display.setCurrent(message);
}
}
}
I'm having a problem with this this part:
Code Java:
if (command == txtspk)
{
for(int a = 0; a < txtWord.length; a++)
{
if(message.getString().equalsIgnoreCase(realWord[a]))
{
message = message.setString(realWord[a]);
}
}
display.setCurrent(message);
}
I don't know how to figure it out. What's the exact syntax should I put there?
Hope someone will help me with this.
Thanks advance.
Re: How to Search, Compare, and Replace text in the TextBox in J2ME?
Re: How to Search, Compare, and Replace text in the TextBox in J2ME?
Re: How to Search, Compare, and Replace text in the TextBox in J2ME?
What exactly is the problem? Are any errors generated? What happens when you run the program?
Where is the realWord array?!
Re: How to Search, Compare, and Replace text in the TextBox in J2ME?
Hello JavaPF,
My problem is how do I compare the string in the textbox? What I mean is, I want to compare the substring to text in the Textbox. If the program found same with the txtWord, it replace the substring of realWord. For example, "tnx" will replace with "thanks" in the Textbox.