Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Replacing a string in a file

Replacing a string in a file

Scheduled Pinned Locked Moved C#
csharptoolshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sanki779
    wrote on last edited by
    #1

    Hi , i want to make a utility using c# similar to replace function in the notepad. i have a file in which i want to replace the all the instances of a string with another string. Help me in doing that ......... thanks and regards sankalp verma

    Sankalp Verma

    L 1 Reply Last reply
    0
    • S sanki779

      Hi , i want to make a utility using c# similar to replace function in the notepad. i have a file in which i want to replace the all the instances of a string with another string. Help me in doing that ......... thanks and regards sankalp verma

      Sankalp Verma

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Open the file and read the contains of the file to a string. Then use, for example: string myText = myText.Replace("apple", "mango");

      S 1 Reply Last reply
      0
      • L Lost User

        Open the file and read the contains of the file to a string. Then use, for example: string myText = myText.Replace("apple", "mango");

        S Offline
        S Offline
        sanki779
        wrote on last edited by
        #3

        But i have to save the contents to the file also......... how do i save them into the file?

        Sankalp Verma

        L 1 Reply Last reply
        0
        • S sanki779

          But i have to save the contents to the file also......... how do i save them into the file?

          Sankalp Verma

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Use StreamWriter. Read MSDN.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups