473,386 Members | 1,753 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,386 software developers and data experts.

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 7820
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Timo Haberkern | last post by:
Hi there, i have some troubles with my TSearch2 Installation. I have done this installation as described in http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_compound_words...
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
5
by: RSBakshi | last post by:
Can any body tell me how to find duplicate lines in C i have tried to find using Binary tree and Text files but not suceeded .. It works for Word but not for lines please help me you can...
3
by: Csaba Gabor | last post by:
I'm comparing the text of (snippets of) web pages which I expect to be quite different or quite similar. In the case where they are similar, I would like to display the more recent one and say...
20
by: dmurray14 | last post by:
Hey guys, I'm a C++ newbie here - I've messed with VB, but I mostly stick to web languages, so I find C++ to be very confusing at times. Basically, I am trying to import a text file, but I want...
10
by: Robert R. | last post by:
Hello, i would like to write a piece of code to help me to align some sequence of words and suggest me the ordered common subwords of them s0 = "this is an example of a thing i would like to...
14
by: inpuarg | last post by:
I want to find a & character using Regex. But not && How can i manage this in c# Quickfind window ? -------------------------------------------------- ne kadar yaşarsan yaşa sevdiğin kadardır...
10
by: Johny | last post by:
I need to find all the same words in a text . What would be the best idea to do that? I used string.find but it does not work properly for the words. Let suppose I want to find a number 324 in...
1
by: Lambda | last post by:
I'm trying to develop several interesting components of a simple search engine follow some text books. A book introduces some ways to compress dictionary, allow it to stay on main memory. In...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...
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.