Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,621 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,019 people online right now. Registration is fast and FREE... Join Now!




String search with wildcards, C++

 
Reply to this topicStart new topic

String search with wildcards, C++, The pattern contains wildcards

babasmith
post 2 Apr, 2006 - 12:14 PM
Post #1


New D.I.C Head

*
Joined: 2 Apr, 2006
Posts: 34


My Contributions


Hello;

I'm trying to write a code for checking whether a string containing wildcards
is a substring of a string T.

I mean for a given pattern P over {a,b,c,d,$} for which $ is a wildcards (of length 1), and a text T over {a,b,c,d}, I'd like to return true iff P appears in T.

Example:

when T=ababcadcdbbad,
_____P=c$$$d$ba
then the answer should be true cause
T=ababcadcdbbad,
____P=c$$$d$ba,

but for P=c$$$d$a then its false
since T=ababcadcdbbad,
________P=c$$$d$_a

and for P=a$$$a the answer should be false cause there is no substring
of T that starts and ends with an 'a' and with (exactly) 3 wildcards between.

I could only find procs for matching a substring without wildcards.

Thanks a lot!

This post has been edited by babasmith: 2 Apr, 2006 - 12:30 PM
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 2 Apr, 2006 - 01:08 PM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,176



Thanked 33 times

Dream Kudos: 25
My Contributions


Well, there are a couple of ways you can do it...if you simply want to use what's available, you can use the C++ string class .find and related methods to locate the start of your possbile substring, then use the substring method to return the proper length, then analyze that substring for the proper pattern by iterating through it...more on the methods used can be read here:
http://www.bgsu.edu/departments/compsci/docs/string.html
http://cplus.about.com/od/beginnerctutorial/l/aa051202d.htm

You can also write your own methods to find wildcards and wrap them up...there are some implementations here:
http://www.codeproject.com/string/wildcmp.asp
http://www.codeguru.com/cpp/cpp/string/alt...icle.php/c2807/
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 03:20AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month