BaseballSTUD
Member
Can anyone explain to me how to use the char primitive data type? I need to check a string for a value and i know you can't do it with the string data type.
Originally posted by: b4u
Have you tried something like:
String testing = "1234abcd";
if(testing.compareTo("1234abcd")==0)
{
System.out.println("Checked OK!");
}
Originally posted by: wjsulliv
If you are trying to check and see if a single character exists in a string you can use the y.charAt(i) function. y.charAt(i) treats the string as an array of characters and returns the character in the i position of string y. Say you had string "ZBCDEFG" And wanted to know if 'V' was in the string. presuming: x = 'V' y = "ZBCDEFG" boolean find(char x, string y) Char test = x String source = y Int stringLen = y.length() boolean answer = false for (int i = 0; i < stringLen; i++) if y.CharAt(i) = x boolean answer = true return answer