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

String to char problems

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Hi

Trying to compare the first charater from SQL return with all the characters from the Alphabet.

I have all the code apart from one problem. The alphabet characters are of type 'char' and the SQL returns of type 'String' (or .substring(0,1) to be exact) but when I try to compare the alphabet letter with the String
( if(char == string)... ) I get a "Incompatible type for char. Can't convert char to java.lang.String" error.

So I need to either find a way to compare a char to a String.substring or a way of converting a String.substring to a char and comparing that to another char.
[ November 30, 2005: Message edited by: Bear Bibeault ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You could compare them as strings.



There is also the String.charAt(int) method...
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#charAt(int)
[ November 30, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
GENIUS!

Sometimes looking at things from a different angle...

Job done,

Cheers.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60781
    
  65

Moved to Java in General (beginner)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String to char problems
 
Similar Threads
Enumerating Letters (a=1,b=2..)
Math.Random() query
Caesar cipher
Programming Diversion 2a: Applying a Key
Unicode Characters