This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

search string from bigger string  RSS feed

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a big string. For example:
bigString="This is big string. Big string is not small";
and i have small string:
smallString="is";
and i have to find how many matches with small string i have in big one.
As a result there should be 2 matches. I have searched the whole string class doc and nothing simple has not come to my mind - it can't be hard.
So does anyone know any good methods to find a match of one string to another?
thnx.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it your home work obviously ?
Something like this:

[ December 01, 2003: Message edited by: Igor Ko ]
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes - it's my homework at school and i'm really out of time. I remember the teacher showd this in class and it was so obvious that i didn't write it down - now i'm in deep ...
I didn't understand the code quite clearly - so if u could add sine comments it would be nice.
Allso ... String.regionMatches() - i don't understand what are the parameters for this fx and can i use it?
ok thnx - need more help.
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at these examples.

Output is 3. Matches all occurances of "is" even the one in "this"


Output is 2.
But if bigstring had contained something like "Do not end a sentence with the word is." it would have returned 0 because of the fullstop.
By using regular expressions we can get around that:

Returns 3. Similar to the first attempt - trying to match "is" also matches "this"


Returns 2
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a newbie, I have a question I'd like to ask,
Is empty for loop " for(; a good programming style?
 
lowercase baba
Bartender
Posts: 12627
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would not use an empty for loop. I use a for loop when i know (or can calculate) the number of iterations i need.
if i want an infinate loop, with a break condition, i'd use

Better/worse/proper is a debate that will go on forever...
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to count the number of times the smallString is found in reverse order as well? For example if the BigString = "Mississipi" and the SmallString = "is". The number of occurrences would be 4. Counting the occurrences of "si" as well.
M(is)(s(i)s)(si)pi.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!