-
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");
}
}
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks