PDA

Click to See Complete Forum and Search --> : insert text ....


Techno
Sep 6th, 2004, 10:25 AM
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?


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....

Mike Hildner
Sep 6th, 2004, 11:08 AM
Take a look at some of the String members - .IndexOf, .Substring, .Replace etc. - should give you what you need.

Techno
Sep 6th, 2004, 11:24 AM
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)

Mike Hildner
Sep 6th, 2004, 12:08 PM
Assuming you're using StreamReader

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