• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I do a partial word search?  RSS feed

 
hrin kuek
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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!

 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!