469,602 Members | 2,048 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Find words in strings

Hi !!

I have to find some words in a string.
I can use string.IndexOf, LastIndexOf, etc, but they are case
sensitive.
And there is another problem : If I found the word, I have to get
three words before and after the found word .

Example:

string s = "This is an example about how to find words in a string";
string wordToFind = "Example"

I have to get : This is an example of how to

Can someone help me???

Thanks
Nov 16 '05 #1
5 7687
Check out the Split method. Should get you on your way.

--
Adam Clauss
ca*****@tamu.edu

"Paula" <ba*******@hotmail.com> wrote in message news:8f**************************@posting.google.c om...
Hi !!

I have to find some words in a string.
I can use string.IndexOf, LastIndexOf, etc, but they are case
sensitive.
And there is another problem : If I found the word, I have to get
three words before and after the found word .

Example:

string s = "This is an example about how to find words in a string";
string wordToFind = "Example"

I have to get : This is an example of how to

Can someone help me???

Thanks

Nov 16 '05 #2
Paula,

you might want to check System.Text.RegularExpressions namespace and Regex
class. It can split strings using general definition of whitespace and word
boundaries, providing you with collection of indexes for found word - see
Matches, Groups and Captures collections there.

HTH
Alex

"Paula" <ba*******@hotmail.com> wrote in message
news:8f**************************@posting.google.c om...
Hi !!

I have to find some words in a string.
I can use string.IndexOf, LastIndexOf, etc, but they are case
sensitive.
And there is another problem : If I found the word, I have to get
three words before and after the found word .

Example:

string s = "This is an example about how to find words in a string";
string wordToFind = "Example"

I have to get : This is an example of how to

Can someone help me???

Thanks

Nov 16 '05 #3
Looks like a job for the regular expression library unless this is a one
time thing and you can hard code it. Either way though I think regexs would
solve it for you.

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/...ity/newsgroups
"Paula" <ba*******@hotmail.com> wrote in message
news:8f**************************@posting.google.c om...
Hi !!

I have to find some words in a string.
I can use string.IndexOf, LastIndexOf, etc, but they are case
sensitive.
And there is another problem : If I found the word, I have to get
three words before and after the found word .

Example:

string s = "This is an example about how to find words in a string";
string wordToFind = "Example"

I have to get : This is an example of how to

Can someone help me???

Thanks

Nov 16 '05 #4
> I can use string.IndexOf, LastIndexOf, etc, but they are case
sensitive.
Just lowercase the string to search and get the positions from there on. Or
use regular expressions as suggested by another poster.

--
venlig hilsen / with regards
anders borum
-- And there is another problem : If I found the word, I have to get
three words before and after the found word .

Example:

string s = "This is an example about how to find words in a string";
string wordToFind = "Example"

I have to get : This is an example of how to

Can someone help me???

Thanks

Nov 16 '05 #5
Hi !!

I think regular expressions are the best choice

Thanks
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Csaba Gabor | last post: by
20 posts views Thread by dmurray14 | last post: by
10 posts views Thread by Robert R. | last post: by
14 posts views Thread by inpuarg | last post: by
10 posts views Thread by Johny | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.