aspose file tools*
The moose likes Beginning Java and the fly likes Find one char in a String ? ? ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Find one char in a String ? ? ? " Watch "Find one char in a String ? ? ? " New topic
Author

Find one char in a String ? ? ?

Douglas Braxton
Ranch Hand

Joined: Jan 28, 2004
Posts: 36
PROBLEM: String s (of indeterminate length) is passed to the method searchString(), the user is prompted to enter a one character search argument name s1. Object of the exercise is to count the number of times
s1 occurs within s, regardless of case h = H, H = h, as it were.
CAN ANYONE FIGURE OUT WHERE I AM GOING WRONG.
THIS IS THE METHOD CALL

THIS IS THE METHOD

COMPILER MESSAGES
MyStrings.java [154:1] char cannot be dereferenced
char s2 = s1.charAt( 0 ).toLowerCase( ) ;
^
MyStrings.java [162:1] char cannot be dereferenced
s2 = ( s1.charAt( 0 ).toUpperCase( ) );
^
2 errors
Errors compiling MyStrings.
THANK YOU
doug
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
toLowerCase() & toUpperCase() can not be used on char returned
by s1.charAt(0);
try
Character.toUpperCase(s1.charAt(0));
Character.toLowerCase(s1.charAt(0));
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Find one char in a String ? ? ?