offside3002's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
6 (0.01 per day)
Joined:
20-January 13
Profile Views:
1,368
Last Active:
User is offline Feb 05 2013 07:34 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   offside3002 has not set their status

Posts I've Made

  1. In Topic: J2ME Textfile Database Problem

    Posted 23 Jan 2013

    View Postfarrell2k, on 23 January 2013 - 07:46 AM, said:

    Nothing. It splits your tokens into single words. You said that you did not want that.

    Yeah but i want it to read a phrase not just a single word. What should i do?
  2. In Topic: J2ME Textfile Database Problem

    Posted 23 Jan 2013

    View Postfarrell2k, on 22 January 2013 - 06:56 AM, said:

    Then don't break it up into single words with this:

    StringTokenizer stText = new StringTokenizer(text," ");
    
    


    This line here separates every your file into single words, so a text file with the data: "How are you | I am OK" would be tokenized as such:

    How
    are
    you
    |
    I
    am
    OK


    So what code should I replace with this sir?
    StringTokenizer stText = new StringTokenizer(text," ");
    
  3. In Topic: J2ME Textfile Database Problem

    Posted 21 Jan 2013

    View Postfarrell2k, on 21 January 2013 - 11:01 PM, said:

    Can you clarify your problem? You have me confused. Please be more specific.


    Sir I want my code to read a phrase in the text file not just a word. And I don't know how to do it.

    here is the code sir that will get the data in the textbox and compare it with the data in the database:
      data = file2();
              text = message.getString();
              StringTokenizer stText = new StringTokenizer(text," ");
    
              while(stText.hasMoreTokens())
              {
                  int found = 0;
                  dbword = stText.nextToken();
                  StringTokenizer st = new StringTokenizer(data,"|");
                  while ((st.hasMoreTokens()) && (found==0))
                  {
                      enterword = st.nextToken();
                      transword = st.nextToken();
                      if(enterword.equalsIgnoreCase(dbword))
                      {
                          found = 1;
                      }
                  }
    
                  if(found==1)
                  {
                      newtxt = newtxt + "" + transword + " ";
                  }
    

    And the code that will look in the database:
     private String file2()
      {
        InputStream is = getClass().getResourceAsStream("translate.txt");
        StringBuffer sb = new StringBuffer();
        try{
          int chars;
          while ((chars = is.read()) != -1)
          {
              sb.append((char) chars);
          }
          return sb.toString();
        }catch (Exception e){}
        return null;
      }
    
  4. In Topic: J2ME Textfile Database Problem

    Posted 21 Jan 2013

    View Postfarrell2k, on 21 January 2013 - 10:20 PM, said:

    Your code is too long go through, but what does sb contain after you read the file with this?

    InputStream is = getClass().getResourceAsStream("textspeak.txt");
        StringBuffer sb = new StringBuffer();
        try{
          int chars;
          while ((chars = is.read()) != -1)
          {
              sb.append((char) chars);
          }
          return sb.toString();
    
    


    This should copy all of the text into the file. Does it?


    Yes sir I think so..
  5. In Topic: J2ME Textfile Database Problem

    Posted 21 Jan 2013

    I'm sorry sir but I copied the wrong code.
    Here is the working code sir for the correcting process:
             data = file();
              text = message.getString();
              StringTokenizer stText = new StringTokenizer(text," ");
    
              while(stText.hasMoreTokens())
              {
                  int found = 0;
                  dbword = stText.nextToken();
                  StringTokenizer st = new StringTokenizer(data,"|");
                  while ((st.hasMoreTokens()) && (found==0))
                  {
                      enterword = st.nextToken();
                      transword = st.nextToken();
                      if(enterword.equalsIgnoreCase(dbword))
                      {
                          found = 1;
                      }
                  }
    
                  if(found==1)
                  {
                      newtxt = newtxt + "" + transword + " ";
                  }
                  else
                  {
    
                      newtxt = newtxt + "" + dbword + " ";
                      alert = new Alert("Please");
                      alert.setString("Please check the spelling or");
                      alert.setString("the word was not found in the database");
                      alert.setTimeout(5000);
                      display.setCurrent(alert);
    
                  }
              }
              if(text.equals(""))
              {
                  newtxt = "";
              }
              temp = newtxt;
              newtxt = "";
              message = new TextBox ("Corrected Message", temp, 2000, TextField.ANY);
              message.addCommand(translate);
              message.addCommand(send);
              message.setCommandListener(this);
              display.setCurrent(message);
    
          }
    

    and the code which will look a word in the text file:
      private String file2()
      {
        InputStream is = getClass().getResourceAsStream("translate.txt");
        StringBuffer sb = new StringBuffer();
        try{
          int chars;
          while ((chars = is.read()) != -1)
          {
              sb.append((char) chars);
          }
          return sb.toString();
        }catch (Exception e){}
        return null;
      }
    


    Yes sir I think sb contained the file from the database...

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

offside3002 has no profile comments yet. Why not say hello?