about searchin' substring in a string 
Author Message
 about searchin' substring in a string

Is there any function that can search a substring (something like strstr)
but match the whole word only??



Mon, 13 Jan 2003 03:00:00 GMT  
 about searchin' substring in a string

Jason,

How about SpanIncluding()?

Or you could use the buffer of the string and search it the old way.

Scott!


Quote:
> Is there any function that can search a substring (something like strstr)
> but match the whole word only??



Mon, 13 Jan 2003 03:00:00 GMT  
 about searchin' substring in a string

I don't think spanincludin' is what i want, and I'm not familiar with the
buffer stuff
what i wanna do is this:

char str[] =    "lazy";
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The quick brown dog jumps over thelazy fox";

so that the whole word "lazy" can only be found in string1


Quote:
> Jason,

> How about SpanIncluding()?

> Or you could use the buffer of the string and search it the old way.

> Scott!



> > Is there any function that can search a substring (something like
strstr)
> > but match the whole word only??



Mon, 13 Jan 2003 03:00:00 GMT  
 about searchin' substring in a string

    Well, there's nothing in the standard library do to that.  Find one or
writing your own calls for more information.  What delimits a "word" in you
view?  Does it begin & end with a space?  What about a comma? a period? a
dash? end-of-string? a tab? a line-feed?

--
Truth,
James Curran
http://www.NJTheater.com          (Professional)
http://www.NovelTheory.com      (Personal)
http://www.BrandsForLess.com   (Day Job)


Quote:
> I don't think spanincludin' is what i want, and I'm not familiar with the
> buffer stuff
> what i wanna do is this:

> char str[] =    "lazy";
> char string1[] = "The quick brown dog jumps over the lazy fox";
> char string2[] = "The quick brown dog jumps over thelazy fox";

> so that the whole word "lazy" can only be found in string1



> > Jason,

> > How about SpanIncluding()?

> > Or you could use the buffer of the string and search it the old way.

> > Scott!



> > > Is there any function that can search a substring (something like
> strstr)
> > > but match the whole word only??



Mon, 13 Jan 2003 03:00:00 GMT  
 about searchin' substring in a string

Why don't you search for " lazy " (note the spaces around it).  You can add
spaces before and after the word you want to look for.


Quote:
> I don't think spanincludin' is what i want, and I'm not familiar with the
> buffer stuff
> what i wanna do is this:

> char str[] =    "lazy";
> char string1[] = "The quick brown dog jumps over the lazy fox";
> char string2[] = "The quick brown dog jumps over thelazy fox";

> so that the whole word "lazy" can only be found in string1



> > Jason,

> > How about SpanIncluding()?

> > Or you could use the buffer of the string and search it the old way.

> > Scott!



> > > Is there any function that can search a substring (something like
> strstr)
> > > but match the whole word only??



Mon, 13 Jan 2003 03:00:00 GMT  
 about searchin' substring in a string

Nothing in the standard library does exactly what you want.
First step is, define exactly what defines a word boundary.

You might look at a regular expression parser.  There are
several free/public/shareware versions on the net.
--
Dan Evens
Standard disclaimers etc. No spam please.



Quote:
> Is there any function that can search a substring (something like strstr)
> but match the whole word only??



Mon, 13 Jan 2003 03:00:00 GMT  
 about searchin' substring in a string
Best I've ever seen is John Maddock's RegEx++.  You can find it here

http://ourworld.compuserve.com/homepages/John_Maddock/regexpp.htm

Joe O'

Quote:

> Nothing in the standard library does exactly what you want.
> First step is, define exactly what defines a word boundary.

> You might look at a regular expression parser.  There are
> several free/public/shareware versions on the net.
> --
> Jason Wong wrote
> > Is there any function that can search a substring (something like
strstr)
> > but match the whole word only??



Mon, 13 Jan 2003 03:00:00 GMT  
 about searchin' substring in a string

Quote:

> I don't think spanincludin' is what i want, and I'm not familiar with
> the buffer stuff what i wanna do is this:
> char str[] =    "lazy";
> char string1[] = "The quick brown dog jumps over the lazy fox";
> char string2[] = "The quick brown dog jumps over thelazy fox";
> so that the whole word "lazy" can only be found in string1

As others have said - figure out just what characters you want to have
delimit each word.  (Searching for " lazy " isn't, imo, what you want:
it wouldn't find lazy at the start of the string, or when followed by
a comma, period, etc.)

Once you determine what characters are delimitters, you can go through
the strings, basically word by word, using 'strtok()' and use strcmp()
to see if your substring/word matches.

MSDN has a snippet of adequate sample code demonstrating strtok(),
albeit their string of separator/delimitter characters is less than
useful for your purposes; I'd suggest something more like :

const char seps[] = " ,;.\"\t\n";

Those should grab most occurences of a word even with common punctuation.

--
-- Chase Vogelsberg, Senior Principal Analyst
-- Logicon Information Systems & Services
-- Wormwood and wine, and the bitter taste of ashes.



Tue, 14 Jan 2003 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. about searchin' substring in a string

2. Searching string for substring question

3. Finding occurance of a substring in a string in C#

4. how to check that string contains substring?

5. Getting Substring from String.LastIndexOf

6. newbie:Occurrences of a substring in a string

7. function to search string for substring

8. How can I extract the substring of string??

9. substring in a string

10. How to insert a substring in a string?

11. How to remove a substring from a string

12. longest substring in a string

 

 
Powered by phpBB® Forum Software