Page 4 of 4 First ... 234
  • Jump to page:
    #46
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    44
    Rep Power
    2
    Originally Posted by MrFujin
    IF you look at these two sentence:
    - This cat is mine
    - This catacomb is mine

    Why is the cat in second sentence not a profane word? you say it is part of a word?
    Yes, I need to find the exact word only, although this doesn't really make sense in terms of real profane words. **** and ****tomb should both be censored.

    How can you see that it is part of a word?
    I guess this is the problem. My methods for doing this are really bad. All I can do is use indexOf to find where it starts...but from there I've tried using length and contentEquals, neither of which worked.

    Generally speaking, how do you separate one word from each other?
    By spacing and punctuation.
  2. #47
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    By spacing and punctuation.
    Find the searched for String: "cat" and then check if it is surrounded (delimited) by spaces or punctuation.
    All I can do is use indexOf
    If you can only use the indexOf() method, it will not be possible to solve this without having hundreds of calls to indexOf() for all possible combinations.
  4. #48
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    44
    Rep Power
    2
    Originally Posted by NormR
    Find the searched for String: "cat" and then check if it is surrounded (delimited) by spaces or punctuation.

    If you can only use the indexOf() method, it will not be possible to solve this without having hundreds of calls to indexOf() for all possible combinations.
    Hmm...well as I said, I am three weeks into an introductory course of Java programming. Trust me, I would like to search for cat with spacings and punctuation, but I really don't know how. This project is actually an extra challenge to something much easier, and all the rest of my projects I completed with ease. My projects aren't due for another week or so, so perhaps my teacher will go over this one in class.
  6. #49
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    It's a multi step process:
    first find the location of "cat" in the sentence/String
    then see if the character in front of "cat" is a space or punctuation
    then see if the character after "cat" is a space or punctuation
    If both those are tests are true, then the found String: "cat" is a word
  8. #50
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    44
    Rep Power
    2
    Originally Posted by NormR
    It's a multi step process:
    first find the location of "cat" in the sentence/String
    Can do this with indexOf, correct?

    then see if the character in front of "cat" is a space or punctuation
    This seems problematic, as indexOf will only take me to the where cat begins. Also, if cat begins a sentence, I will get run time errors.

    then see if the character after "cat" is a space or punctuation
    If both those are tests are true, then the found String: "cat" is a word
    I can probably figure this part out, but the middle part is an issue for me.
  10. #51
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    if cat begins a sentence
    Use the value returned by indexOf() to determine that.
    Also that value with the length() method would tell you if cat ends a sentence.
    To see: write a sentence with cat at the end, write numbers under each character and see what math expression would tell you if cat is at the end.
  12. #52
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    44
    Rep Power
    2
    (space)cat(space)

  14. #53
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    If cat is at the start of the sentence, there will not be a space:
    "cat in a hat"
    Leave off the spaces in the indexOf() call. Then use the substring method to get the character before and the one after.
  16. #54
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    44
    Rep Power
    2
    Can't I add " " before and after the string then test for (space)cat(space)? Seems like it will work.
  18. #55
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    That would fix that case.
    What about when in 's: " 'cat' in a hat"
    or followed by .: the cat.
    or followed by ,: a cat, rat or bat
    etc
  20. #56
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    44
    Rep Power
    2
    Its just the exact form of cat. Mercifully, I don't have to deal with punctuation or apostrophe's. This should fix the problem for me.

    Perhaps once I show you my working program, you could show me (with code) the method you're talking about? If you don't mind of course. I think its a little above my current abilities.
  22. #57
  23. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    You'll have to come back to this problem after you study the other String class methods.
  24. #58
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    44
    Rep Power
    2
    Ahh. Many thanks for your help.
  26. #59
  27. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    You're welcome.
Page 4 of 4 First ... 234
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo