ASCII code for String in Java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: ASCII code for String in Java

  1. #1
    Michelle Guest

    ASCII code for String in Java


    Hi,

    I will like to know how to convert a String value into ASCII value?
    Right now I'm trying to read JSP file, and string tokenise words within tags(e.g.
    <tr>), and then write these words into a text file. The scope of the program
    is to translate words in the JSP file into chinese.
    Below is my program, which I think the errors lies on the coding part. I
    need to implement hashtable into it.
    Please reply as soon as possible, as this is urgent.

    ArrayList list=new ArrayList();
    try
    {
    //To read in the jsp file information
    FileReader file=new FileReader("C:\\petra\\AddOu.jsp");
    BufferedReader bReader=new BufferedReader(file);
    FileWriter writeFile=new FileWriter("C:\\petra\\English.text");
    BufferedWriter bWriter=new BufferedWriter(writeFile);
    String line;
    String s="";
    while((line=bReader.readLine())!=null)
    {
    list.add(line);
    }
    for(int i = 0; i<list.size(); i++)
    {
    String ln=(String)list.get(i);
    //To String tokenize each line, until it find >
    StringTokenizer sToken=new StringTokenizer(ln,"<");
    while(sToken.hasMoreTokens())
    {
    Byte byteString=new Byte(sToken.nextToken());
    if(byteString!=null)
    {
    String a=new String(byteString.toString());
    bWriter.write(a);
    }
    }
    }
    }
    catch(IOException e)
    {
    System.out.println("catch io exception");
    }
    catch(NumberFormatException e)
    {
    System.out.println("catch number format exception");
    }
    }

  2. #2
    Ruchi Dhar Guest

    Re: ASCII code for String in Java


    I suggest you should use Regular Expressions to solve these kind of text parsing.
    Regular Expressions are very powerful and very easy to use for any kind
    of pattern matchings.

    Here are couple of Regular Expression packages for java

    1)Regexp (http://jakarta.apache.org/regexp/index.html)
    2)ORO (http://jakarta.apache.org/oro/index.html)
    3)GNU Regex (http://www.crocodile.org/~sts/Rex)
    4)JRegex (http://jregex.sourceforge.net)

    In JRegex there is a pattern tokenizer which I guess is very handy for your
    use.



    "Michelle" <michellelimmx@hotmail.com> wrote:
    >
    >Hi,
    >
    >I will like to know how to convert a String value into ASCII value?
    >Right now I'm trying to read JSP file, and string tokenise words within

    tags(e.g.
    ><tr>), and then write these words into a text file. The scope of the program
    >is to translate words in the JSP file into chinese.
    >Below is my program, which I think the errors lies on the coding part. I
    >need to implement hashtable into it.
    >Please reply as soon as possible, as this is urgent.
    >
    >ArrayList list=new ArrayList();
    >try
    >{
    > //To read in the jsp file information
    > FileReader file=new FileReader("C:\\petra\\AddOu.jsp");
    > BufferedReader bReader=new BufferedReader(file);
    > FileWriter writeFile=new FileWriter("C:\\petra\\English.text");
    > BufferedWriter bWriter=new BufferedWriter(writeFile);
    > String line;
    > String s="";
    > while((line=bReader.readLine())!=null)
    > {
    > list.add(line);
    > }
    > for(int i = 0; i<list.size(); i++)
    > {
    > String ln=(String)list.get(i);
    > //To String tokenize each line, until it find >
    > StringTokenizer sToken=new StringTokenizer(ln,"<");
    > while(sToken.hasMoreTokens())
    > {
    > Byte byteString=new Byte(sToken.nextToken());
    > if(byteString!=null)
    > {
    > String a=new String(byteString.toString());
    > bWriter.write(a);
    > }
    >}
    >}
    > }
    > catch(IOException e)
    > {
    > System.out.println("catch io exception");
    > }
    > catch(NumberFormatException e)
    > {
    > System.out.println("catch number format exception");
    > }
    > }



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center