How can i store the contents of a string variable to a text file ?
How can i search in a string variable for specific text for example find if the word book is in the string?
To save the file to text you can do:
System.IO.File.WriteAllText("C:\your_path\your_file", Your_contents);
To Search for something in the string:
var position = Your_string.IndexOf("Book");
If position equals -1 then what you are searching for isn't there.
In the off chance you are actually stumped on where to find this information, it's as simple as:
System.IO.File.WriteAllText(myPathToTheFile, myStringToWrite);
To find a string within another string, you would simply do this:
myString.Contains(someOtherString); // boolean
myString.IndexOf(someOtherString); // find the 0 based index of the target string
File.WriteAllText("MyFile.txt", myString); // Write all string to file
var wordBookIndex = myString.IndexOf("book"); // If the string is found, index != -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With