| 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: 56540
|
|
|
Moved to Java in General (beginner)
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: String to char problems
|
|
|