-
insert text ....
hi there
I have a text file, this text file may change, however it will have a % character in it.
this % character, will indicate that some filename / text goes in, so it replaces the %.
how can i do this in C#?
I have a text box, where the information goes, and wish to update that info regardless of what this "main" file is, but replaces the % with some other text.
any ideas?
[edit]so really, we need to know if there is some sort of INSTR (instring) function like VB which will look at the string and replace it with some text of your choice when it finds a particular string you wish to replace it with....[/edit]
-
Take a look at some of the String members - .IndexOf, .Substring, .Replace etc. - should give you what you need.
-
replace....string builder works :) thanks!
another thing is, how to i detect until its reached to the end of the file?
i am using readline (because i need to add some stuff so thats why im not using readtoend)
-
Assuming you're using StreamReader
Code:
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
Something like that, which, BTW, was copied and pasted from MSDN. MSDN is a great resource, it's worth searching.
Mike