• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I do a partial word search?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a customer's name as an attribute of a reservation object stored in my vector of reservation objects. My current search only does an exact match of a customer name. How do I do a partial word search eg. if my customer name is danielle and I only key in dan, how do i get it to return danielle?

Hope to hear from someone soon! Thank you!

 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This page should be able to help.
[ April 01, 2005: Message edited by: Ken Loh ]
 
hrin kuek
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
erm sorry... I feel lost lookin at tt page.. if it's not too much trouble, could you please give me an example?

Thanks again!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just using String methods, try haystack.indexOf(needle) to see if a small string is included in a large one.

The Pattern reference given above is all about regular expressions. RegEx is great fun and can do very powerful pattern matching. It looks scary but is fairly easy to pick up by copying examples. Try this Sun Tutorial or google for others to get started.
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stan's suggestion is good. indexOf() will suffice for your case ( and for many other cases).

If you're still keen in using regular expression from the link that I'd posted, you could use it with String's match() method.

After reading Stan's suggestion, I think you should just use indexOf() to keep things simple.

Originally posted by hrin kuek:
erm sorry... I feel lost lookin at tt page.. if it's not too much trouble, could you please give me an example?

Thanks again!

 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic