Results 1 to 4 of 4

Thread: insert text ....

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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]
    Last edited by Techno; Sep 6th, 2004 at 10:38 AM.

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Take a look at some of the String members - .IndexOf, .Substring, .Replace etc. - should give you what you need.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    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)

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width