473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Finding string with "wild" characters in another string

Hello!

I'm looking for efficient code or site where I can find code for finding one
string in another string. String which I search should have "wild"
characters like '?' for any one char and '*' for any string of characters.

I'm looking for way to effective getting string from text file and then
searching it like I write above.

Thanks in advance for any helps, notices or sites

--

Best regards
Pawe Chmielarz
----------------------------------
pa***@itproject.com.pl
Jul 22 '05 #1
2 3110

"Pawe" <pa***@itproject.com.pl> wrote in message
news:cc**********@sunflower.man.poznan.pl...
Hello!

I'm looking for efficient code or site where I can find code for finding one string in another string. String which I search should have "wild"
characters like '?' for any one char and '*' for any string of characters.

I'm looking for way to effective getting string from text file and then
searching it like I write above.

Thanks in advance for any helps, notices or sites

http://www.boost.org/libs/regex/doc/index.html

john
Jul 22 '05 #2
"Pawe" <pa***@itproject.com.pl> wrote in message
news:cc**********@sunflower.man.poznan.pl...
Hello!

I'm looking for efficient code or site where I can find code for finding one string in another string. String which I search should have "wild"
characters like '?' for any one char and '*' for any string of characters.

I'm looking for way to effective getting string from text file and then
searching it like I write above.

Thanks in advance for any helps, notices or sites


Hope this helps. I pulled it out of the project with some custom types
(e.g. char*) and changed them here to built-in types, but apologize if
it won't compile as is. The algorithm has been tested and is in production.
Unfortunately you will not get the found matched substrings as with
regular expressions, but is quite fast.

int wildMatch(char *wild, char *text)
{
enum { UNSYNC,SYNC,START };
char *lastwild, *lasttext; /* last synced position in CMP mode */
unsigned state, size; /* SEARCH mode(0), CMP mode otherwise */

for(state=START; ; )
{
if(*wild == 0) { /* is end of wildargs ? */
if(state!=UNSYNC && *text==0) /* is there text in synced mode?
*/
return 0;
if(state == START) /* there was no asterisk at all */
return -1;
/* compiler gives warning: possible use before definition */
size = wild-lastwild; /* size of the string */
return strcmp(lastwild, lasttext+strlen(lasttext)-size);
}

if(*text == 0) { /* is end of text ? */
while(*wild=='*') wild++; /* skip all asterisks */
return *wild==0 ? 0 : 1; /* wild is at the end - success */
}

if(state != UNSYNC)
{
/* sync is when texts are synchronized */
if(*wild == '*') {
while(*wild=='*') wild++;/* skip all consequent asterisks */
lastwild = wild; /* remember last positions */
lasttext = text;
state = UNSYNC; /* unsynchronize */
} else
if(*wild == *text || *wild == '?') {
wild++; /* they are same, move to nexts */
text++;
} else {
if(state == START) /* they don't match (no wildcard) */
return *wild-*text;
wild = lastwild; /* not equal chars in CMP mode */
text = ++lasttext; /* go back to last good */
state = UNSYNC; /* unsynchronize */
}
}
else
{
/* non-sync is looking first match */
if(*wild == *text) {
lasttext = text; /* remember last good position */
state = SYNC; /* synchronized again */
} else
text++;
}
}
}
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Smithz | last post by:
Hello there, Summary: How far can you go with SQL Select queries using like clauses with wildcard characters. Can you apply anything like regular expressions? Full details: On a Intranet...
9
by: Pawe | last post by:
Hello! I'm looking for efficient code or site where I can find code for finding one string in another string. String which I search should have "wild" characters like '?' for any one char and...
1
by: Tom Wild | last post by:
Hi I am trying to create a webform that connects to an Access database. If I use the connection string: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Gizmo\Gizmo.mdb" Then the application...
4
by: SatishPasala | last post by:
hi I am tring to remove all the wild characters from a string. Is there any short method to remove them in a single go. I am right now tring to replace one by one. Ex (999) 999-9999 I...
3
by: Shilpa | last post by:
Hi, I have a OpenFileDialog on my windows form whose filter is *.*. I want the users to be able to further filter the files by giving *.doc or *.zip etc in the "file name" field of the dialog...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
2
by: Papkin | last post by:
Hi if ( eregi("^/a-zA-Z0-9±ęćłń󶿼ˇĆĘŁŃÓ¦¬Ż\.\/\/-]{2,65}$","Merry & Cat") ) return true; else return false; I'd like to match also "&" but this regexp above does not do...
9
by: Sreeraj | last post by:
hi, I am a beginner in Python. I wish to know how can i filter a list of strings using wild characters.ie Lets say i have list countries = . I need only the list of string starting with 'a'. ...
7
by: W. eWatson | last post by:
Is it possible to do a search for a wild card string in another string. For example, I'd like to find "v*.dat" in a string called bingo. v must be matched against only the first character in bingo,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.