473,626 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3133

"Pawe" <pa***@itprojec t.com.pl> wrote in message
news:cc******** **@sunflower.ma n.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***@itprojec t.com.pl> wrote in message
news:cc******** **@sunflower.ma n.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,STA RT };
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!=UNSYN C && *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
13357
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 website, I request a code from a user which is then compared with a code in an ADO access database.
9
472
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 '*' 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
1
3478
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 connects to the database and downloads data fine but when I try to fire an Update command I get the following error: "Problem firing System.Data.OleDb.OleDbCommand - Operation must use an updateable query"
4
2454
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 need 9999999999 with out all the charecters and spaces. I am trying
3
4810
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 (Just like it happens in the open file dialog of MS Word) Currently, if the user enters a wild card character in the file name field, it is throwing an exception with the message "Illegal characters in path". Please let me know how to achieve the...
169
9047
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 untaking to create a toolchain for it. Way back when, there used to be something called "Small C". I wonder if the creator(s) of that would want to embark on creating a nice little Small C++ compiler devoid of C++ language features that make...
2
1453
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 this, adding \& does not help. Any ideas?
9
18044
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'. thank you
7
9253
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, and not simply found somewhere in bingo, as might be the case for "*v*.dat". -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet
0
8259
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8192
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8696
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8358
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7188
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6119
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.