char = string???

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2006
Posts: 2
Reputation: rootadmen is an unknown quantity at this point 
Solved Threads: 0
rootadmen rootadmen is offline Offline
Newbie Poster

char = string???

 
0
  #1
Sep 3rd, 2006
Im trying to cast a char to a string, but if i just define equality, the complier says incompatible types.
I looked in my textbook but it only shows how to cast ints and doubles.
I have to write a class that takes a char and a String. It then searches the string for the char and returns a boolean.
Im useing a scanner to do this, and it will only accept a string, not a char. Maybe I'm going about this all wrong, if so, please point me in the right direction.

Thanks
Colin
  1. public static boolean isThere(char sreachChar, String stringToSreach)
  2. {
  3. String stringToSreachLower = stringToSreach.toLowerCase();
  4. String stringToSreachUpper = stringToSreach.toUpperCase();
  5.  
  6. String sreachString=sreachChar;//WTF???
  7.  
  8. Scanner stringScannerLower = new Scanner(stringToSreachLower);
  9. Scanner stringScannerUpper = new Scanner(stringToSreachUpper);
  10.  
  11. String text = key.readWord();//inputs up to white space
  12. key.readLine();//Clear input buffer
  13.  
  14. if(stringScannerLower.findInLine(sreachString) == sreachString | stringScannerUpper.findInLine(sreachString) == sreachString)
  15. {
  16. return(true);
  17. }
  18. else
  19. return(false);
  20. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 2
Reputation: rootadmen is an unknown quantity at this point 
Solved Threads: 0
rootadmen rootadmen is offline Offline
Newbie Poster

Re: char = string???

 
0
  #2
Sep 3rd, 2006
Nevermind, I found the solution here:
http://www.artima.com/legacy/answers...sages/265.html
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: char = string???

 
0
  #3
Sep 4th, 2006
this is Java, not C.
A String isn't a char so you can't cast one to the other.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC