Results 1 to 9 of 9
  1. #1
    jigglywiggly is offline Senior Member
    Join Date
    Nov 2008
    Posts
    105
    Rep Power
    0

    Default 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?

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    first of all.

    this is a wrng representation

    String "cool" = hello

    it shld be

    String cool = "hello"; instead.

    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?"

    So can you please elaborate?

  3. #3
    jigglywiggly is offline Senior Member
    Join Date
    Nov 2008
    Posts
    105
    Rep Power
    0

    Default

    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.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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?

  5. #5
    jigglywiggly is offline Senior Member
    Join Date
    Nov 2008
    Posts
    105
    Rep Power
    0

    Default

    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()

  6. #6
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    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(..)

  7. #7
    bigj is offline Member
    Join Date
    Dec 2009
    Posts
    68
    Rep Power
    0

    Default

    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

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Silly characters like space, carriage return, e.t.c

  9. #9
    bigj is offline Member
    Join Date
    Dec 2009
    Posts
    68
    Rep Power
    0

Similar Threads

  1. Quick and Easy Job.
    By Scottyb in forum Jobs Offered
    Replies: 3
    Last Post: 08-11-2009, 04:48 PM
  2. Quick and easy question about SQL databases.
    By mainy in forum New To Java
    Replies: 3
    Last Post: 08-05-2009, 03:04 PM
  3. New to Java and have an easy question
    By JBOY08 in forum New To Java
    Replies: 1
    Last Post: 11-19-2008, 08:40 PM
  4. quick easy question
    By jmHoekst in forum New To Java
    Replies: 1
    Last Post: 06-19-2008, 04:28 PM
  5. Easy question
    By JavaNoob in forum New To Java
    Replies: 10
    Last Post: 08-03-2007, 11:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •