The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Page 3 -
Filtering Strings
Page 3 - Discuss Filtering Strings in the Java Help forum on Dev Shed. Filtering Strings Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 11th, 2013, 04:51 PM
|
|
Contributing User
|
|
Join Date: Feb 2013
Posts: 44
Time spent in forums: 11 h 44 m 41 sec
Reputation Power: 1
|
|
Ahh, I will do some more later. It sounds like I have been using the indexOf method completely wrong. 
|

February 11th, 2013, 05:20 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
The indexOf() method would find the location of "cat". Then look at the character before it and the character after it. Their identity would say if "cat" was a word or was a subpart of another larger word.
|

February 11th, 2013, 05:55 PM
|
|
Contributing User
|
|
Join Date: Feb 2013
Posts: 44
Time spent in forums: 11 h 44 m 41 sec
Reputation Power: 1
|
|
|
I still don't get it. So I get various numbers that relate to index positions:
cat is happy
where icat
hi cat whats up
turn cat
....0, 7, 3, 5, etc...I don't understand what that does for me. I can get the length but...I don't see how that helps me any either. Yes, it should be three, but it will be that way with cat or catacomb.
|

February 11th, 2013, 06:33 PM
|
 |
Lord of the Dance
|
|
|
|
|
If you look at second example with the icat.
You got the index of 7, what result will you get if you look at the character in front of c (index-1)? what does this tell related/compared to what is a valid delimiter?
|

February 11th, 2013, 06:41 PM
|
|
Contributing User
|
|
Join Date: Feb 2013
Posts: 44
Time spent in forums: 11 h 44 m 41 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by MrFujin
You got the index of 7, what result will you get if you look at the character in front of c (index-1)? |
charAt(6) = i
Quote: | what does this tell related/compared to what is a valid delimiter? |
It tells me that every possible character is a possibility before and after the word cat. Given words like catacomb, I don't know how to tell with them...This is probably where I am going wrong.
|

February 11th, 2013, 06:41 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
Do you know what the term "delimiter" means?
Most words we type are delimited by spaces.
Other delimiters are the beginning of a sentence.
Other delimiters for words are comma and period.
If a String is delimited by any of these characters then it is a word. If it has other delimiters then it is NOT a word.
Your search is for words like cat not category. In category, cat has a following delimiter of e which makes the cat in category not a word.
Last edited by NormR : February 11th, 2013 at 06:43 PM.
|

February 11th, 2013, 07:33 PM
|
|
Contributing User
|
|
Join Date: Feb 2013
Posts: 44
Time spent in forums: 11 h 44 m 41 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by NormR Do you know what the term "delimiter" means?
Most words we type are delimited by spaces.
Other delimiters are the beginning of a sentence.
Other delimiters for words are comma and period.
If a String is delimited by any of these characters then it is a word. If it has other delimiters then it is NOT a word.
Your search is for words like cat not category. In category, cat has a following delimiter of e which makes the cat in category not a word. |
Hardly, we never went over them in class, although there was a brief mention of them in Chapter 2. I messed around with them, but they didn't make a lot of sense to me. Should I be using a delimiter in my program?
If I use cat as delimiter, it will cutoff the rest of the input from wherever cat ends up getting typed.
|

February 11th, 2013, 07:51 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
The delimiters I have been talking about are single characters that mark the ends of a String to identify words. The String "cat" would not be called a delimiter.
In the String: "xHerex" the character x is the delimiter for the word: Here
The delimiter I am talking has nothing to do with any args to methods in java. It is being used as a common English word.
|

February 11th, 2013, 08:21 PM
|
|
Contributing User
|
|
Join Date: Feb 2013
Posts: 44
Time spent in forums: 11 h 44 m 41 sec
Reputation Power: 1
|
|
|
You've lost me, boss.
|

February 11th, 2013, 08:37 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
What characters delimit the String: "Here" in the String: "xHerez"
What character is before "Here" and what character is after "Here"?
|

February 11th, 2013, 09:05 PM
|
|
Contributing User
|
|
Join Date: Feb 2013
Posts: 44
Time spent in forums: 11 h 44 m 41 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by NormR What characters delimit the String: "Here" in the String: "xHerez" |
x and z
Quote: |
What character is before "Here" and what character is after "Here"? |
x is before and z is after.
|

February 11th, 2013, 09:18 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
Given the String: "xherez"
Now if we change the x to a t and the z to a space we get: "there "
Does that String have the word here in it?
Next change the x to a space and the z to a space we get: " here "
Does that String have the word here in it?
Next change the x to a space and the z to a period we get: " here."
Does that String have the word here in it?
Notice how what values the delimiting characters have determines if there is a word or not. spaces or a period make a word, others do not.
|

February 11th, 2013, 09:39 PM
|
|
Contributing User
|
|
Join Date: Feb 2013
Posts: 44
Time spent in forums: 11 h 44 m 41 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by NormR Given the String: "xherez"
Now if we change the x to a t and the z to a space we get: "there "
Does that String have the word here in it? |
Yes
Quote:
Next change the x to a space and the z to a space we get: " here "
Does that String have the word here in it? |
Yes
Quote:
Next change the x to a space and the z to a period we get: " here."
Does that String have the word here in it? |
Yes
Quote: |
Notice how what values the delimiting characters have determines if there is a word or not. spaces or a period make a word, others do not. |
I follow this, at least I think I do, thank you...but I still have no idea how this relates to cat and category.
|

February 12th, 2013, 03:17 AM
|
 |
Lord of the Dance
|
|
|
|
|
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?
How can you see that it is part of a word?
Generally speaking, how do you separate one word from each other?
|

February 12th, 2013, 05:48 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | how this relates to cat and category. |
Its a way to find the difference. You want to detect the word cat and not the word category.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|