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
  1. Home
  2. General Programming
  3. C#
  4. How to add string to file at nth line at 5th index using File stream

How to add string to file at nth line at 5th index using File stream

Scheduled Pinned Locked Moved C#
tutorialquestioncsharpdatabasecom
2 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.
  • C Offline
    C Offline
    Chintan Desai
    wrote on last edited by
    #1

    Hi guys, I am new to file operation in .NET.I read few articles on FileStream class.I know seek() method.But guys how can i insert some text say "xyz" at 2nd line and at 5th index.Example File1.txt --------- hello billgates how r u? --------- output : hello billgxyzates how r u? Solution wud be appreciated. Thank u in advance

    Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)

    C 1 Reply Last reply
    0
    • C Chintan Desai

      Hi guys, I am new to file operation in .NET.I read few articles on FileStream class.I know seek() method.But guys how can i insert some text say "xyz" at 2nd line and at 5th index.Example File1.txt --------- hello billgates how r u? --------- output : hello billgxyzates how r u? Solution wud be appreciated. Thank u in advance

      Regards Chintan www.visharadsoft.com (Nothing is so purify as KNOWLEDGE)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can't insert text. You need to read the whole file, insert the text in memory, and write it out again. There may be a helper method that does that, but under the hood, that's what it will do. If there is a helper method, it will be a File. method ( static on the File class )

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      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