File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Problem related to Ascii Value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem related to Ascii Value" Watch "Problem related to Ascii Value" New topic
Author

Problem related to Ascii Value

Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Hi,

I have String and int value which is nothing but ascii value for particular character. I want to search that character in String.
Problem is my int variable will have always value of any character A-Z means 65 to 90, suppose I have 65 and my string do not have 'A' in it,but has 'a'.Then I want to have index of 'a'.
How should I do this?
Is any java class gives me character corresponding to given int value..

Thanx in advance..


~ Anand,
SCJP 1.5, SCWCD 1.5
Matti Poro
Ranch Hand

Joined: Dec 03, 2005
Posts: 41
You can convert an int to char with an explicit cast: char ch = (char) intvalue;

The lowercase letter is: char ch = (char) (intvalue + 32);
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Converting between integers and characters, simply by casting, is rather dodgy, unless you are really sure that your integer can only represent a character in the 7-bit ASCII set. Might your application ever be internationalised? If so, you should seek a better approach.

Also, converting between upper and lower case by adding 32 to the integer value is bad, for similar reasons. Use Character.toLowerCase() and Character.toUpperCase(). These work correctly for international characters. They are also clearer to the reader of your code.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem related to Ascii Value