Hi,

I am writing a program that needs to search particular strings in a text file. The strings are typed in a text box by the user and then when the text file is opened, using fileDialog, the program searches that file using the string in the text box. I have done this currently with the String->Contains function.

Here is the code I used currently

if(Form1::wordsearch->Text != "") {
String ^wrdsrch;
wrdsrch = Form1::wordsearch->Text;if (line->Contains(wrdsrch)) { ...

the last line in the if statement is the one that does the search. I want to make sure that the string is exactly and only exactly the same string in the document as the user put it. How do I write a piece of code that will match each letter for me and then if the letters don't match, go to the next word in the line and so on until an exact match has been found in that line of text. Then going on to the next line. I only need to know if the exact word is in a line of the document and then going on to the next line of that document.

This is in Visual C++ .net the express version from Microsoft.

Can anybody help me with this??

Thanks in advance,
Tony

Edited 3 Years Ago by happygeek: fixed formatting

Don't know if it helps, but I just wrote something very very simple in C# 2005 express, you may want to consider switching over to it of you want. If not maybe someone else can help you out in C++.

StreamReader sr = new StreamReader(@"File.txt", true);
 
String curString = "";
String totalString = "";
while (!sr.EndOfStream)

{[INDENT]curString = sr.ReadLine();[/INDENT]

[INDENT]if (curString.Contains(";"))[/INDENT]

[INDENT]{[INDENT]curString = curString.Replace(";", "Comment - ");[/INDENT]
}
if(curString.EndsWith("\\"))

{[INDENT]curString = curString.Replace("\\", "\n"); [/INDENT]
}
 
totalString += curString; 

[/INDENT]}

> How do I write a piece of code that will match each letter for me and then if the letters don't match, go to the next word in the line and so on until an exact match has been found in that line of text.

And what have you tried?

> How do I write a piece of code that will match each letter for me and then if the letters don't match, go to the next word in the line and so on until an exact match has been found in that line of text.

And what have you tried?

I have only used the 'contains' function from the String class. I know that i can be done using a for loop and going through each charachter of the string at a time, i just don't know how to write it. That's what I need help with?

This question has already been answered. Start a new discussion instead.