File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to char problems

 
Kevin P Smith
Ranch Hand
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Kevin P Smith
Ranch Hand
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GENIUS!

Sometimes looking at things from a different angle...

Job done,

Cheers.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Java in General (beginner)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic