# Quick easy question

• 01-04-2010, 07:18 AM
jigglywiggly
Quick easy question
Just wondering, how would you check if a String has a character at a certain poisition?

Say String "cool" = hello

how would I make the equivelent of this:

if(cool.chatAt(4)!=null) {
doThis();
}

I know I can't use null with this, what would I use instead of null here?
• 01-04-2010, 07:37 AM
[RaIdEn]
first of all.

this is a wrng representation

String "cool" = hello

it shld be

2nd of all characters are primitive types that have only 1 value either a letter or a number.

So your question doesnt make sense. "how would you check if a String has a character at a certain poisition?"

• 01-04-2010, 07:46 AM
jigglywiggly
I realize the thing about the String, I am just writing shorthand.

I am saying, the string "cool".

How can I check if at the position(4) if there is a char there or not.
• 01-04-2010, 07:59 AM
r035198x
A String has characters for it's entire length. Are you trying to check for certain types of characters instead? e.g Non visible characters?
• 01-04-2010, 08:26 AM
jigglywiggly
Forget the question, I was just having 2 types of strings inputed, one is one character shorter than the other. I was just trying to check if there was a character there on the shorter string. Doesn't matter though, I will just use .length()
• 01-04-2010, 09:00 AM
[RaIdEn]
oh..at that case you can use the strng length which would be a common way.

you can also charat(..)
just try combo of while loop and charat(..)
• 01-04-2010, 01:55 PM
bigj
Quote:

A String has characters for it's entire length. Are you trying to check for certain types of characters instead? e.g Non visible characters?
sir excuse me what does it mean by non visible characters
• 01-04-2010, 01:58 PM
r035198x
Silly characters like space, carriage return, e.t.c
• 01-04-2010, 04:34 PM
bigj
thanks..! :D thought it was something