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. Rich Text Box [modified]

Rich Text Box [modified]

Scheduled Pinned Locked Moved C#
csharpjavascript
4 Posts 3 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.
  • R Offline
    R Offline
    rowdykuttan
    wrote on last edited by
    #1

    Dear All, Am having Nearly 470 Text files. I want to do a text replacement in all these files. There are 60-80 replacements in each page. here is sample contents of one of the file [](javascript:popUp\('../images/Backpack/158-62.jpg'\)) [](javascript:popUp\('../images/Backpack/194-62.jpg'\))

    [](javascript:popUp\('../images/Backpack/106-62.jpg'\))[Here for value XXX-XX it must be replaced with the .JPG file name which comes below. I have Created a Desktop Application in C# to do this. its getting converted but the alignment changes happens for files. Am doing it this way 1) Am Opening Text File private const string FILE_TAG = "[FILE]"; private const string FILENAME_TAG = "[NAME]"; private const string FILE_FILTER = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; private bool m_bIncludeRelativePath = false; private bool m_bRecurseSubDirs = false; private string m_sFilePath = string.Empty; private string m_sSourcePath = string.Empty; private string m_sInputTemplate = string.Empty; string sPingPath = string.Empty; public TEXT_REPLACE() { InitializeComponent(); } private string GetOpenFilePath() { string sFilePath = string.Empty; OpenFileDialog openFile = new OpenFileDialog(); openFile.Title = "Open File"; openFile.Filter = FILE_FILTER; if (openFile.ShowDialog() == DialogResult.OK) { sFilePath = openFile.FileName; sPingPath = openFile.FileName; } return sFilePath; //return sPingPath; } private string LoadFile(string sFilePath) { FileStream file = null; StreamReader sr = null;](javascript:popUp('../images/Backpack/106-62.jpg'))

    C L 2 Replies Last reply
    0
    • R rowdykuttan

      Dear All, Am having Nearly 470 Text files. I want to do a text replacement in all these files. There are 60-80 replacements in each page. here is sample contents of one of the file [](javascript:popUp\('../images/Backpack/158-62.jpg'\)) [](javascript:popUp\('../images/Backpack/194-62.jpg'\))

      [](javascript:popUp\('../images/Backpack/106-62.jpg'\))[Here for value XXX-XX it must be replaced with the .JPG file name which comes below. I have Created a Desktop Application in C# to do this. its getting converted but the alignment changes happens for files. Am doing it this way 1) Am Opening Text File private const string FILE_TAG = "[FILE]"; private const string FILENAME_TAG = "[NAME]"; private const string FILE_FILTER = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; private bool m_bIncludeRelativePath = false; private bool m_bRecurseSubDirs = false; private string m_sFilePath = string.Empty; private string m_sSourcePath = string.Empty; private string m_sInputTemplate = string.Empty; string sPingPath = string.Empty; public TEXT_REPLACE() { InitializeComponent(); } private string GetOpenFilePath() { string sFilePath = string.Empty; OpenFileDialog openFile = new OpenFileDialog(); openFile.Title = "Open File"; openFile.Filter = FILE_FILTER; if (openFile.ShowDialog() == DialogResult.OK) { sFilePath = openFile.FileName; sPingPath = openFile.FileName; } return sFilePath; //return sPingPath; } private string LoadFile(string sFilePath) { FileStream file = null; StreamReader sr = null;](javascript:popUp('../images/Backpack/106-62.jpg'))

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

      I'm not sure I follow, but I'd use File.ReadAllText and File.WriteAllText ( or ReadAllLines/WriteAllLines ) to read/write the file. And if the changes are known, I'd just use string.Replace to do them.

      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
      • R rowdykuttan

        Dear All, Am having Nearly 470 Text files. I want to do a text replacement in all these files. There are 60-80 replacements in each page. here is sample contents of one of the file [](javascript:popUp\('../images/Backpack/158-62.jpg'\)) [](javascript:popUp\('../images/Backpack/194-62.jpg'\))

        [](javascript:popUp\('../images/Backpack/106-62.jpg'\))[Here for value XXX-XX it must be replaced with the .JPG file name which comes below. I have Created a Desktop Application in C# to do this. its getting converted but the alignment changes happens for files. Am doing it this way 1) Am Opening Text File private const string FILE_TAG = "[FILE]"; private const string FILENAME_TAG = "[NAME]"; private const string FILE_FILTER = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; private bool m_bIncludeRelativePath = false; private bool m_bRecurseSubDirs = false; private string m_sFilePath = string.Empty; private string m_sSourcePath = string.Empty; private string m_sInputTemplate = string.Empty; string sPingPath = string.Empty; public TEXT_REPLACE() { InitializeComponent(); } private string GetOpenFilePath() { string sFilePath = string.Empty; OpenFileDialog openFile = new OpenFileDialog(); openFile.Title = "Open File"; openFile.Filter = FILE_FILTER; if (openFile.ShowDialog() == DialogResult.OK) { sFilePath = openFile.FileName; sPingPath = openFile.FileName; } return sFilePath; //return sPingPath; } private string LoadFile(string sFilePath) { FileStream file = null; StreamReader sr = null;](javascript:popUp('../images/Backpack/106-62.jpg'))

        L Offline
        L Offline
        Lutoslaw
        wrote on last edited by
        #3

        IMHO it's a single line of code:

        File.WriteAllText(file, File.ReadAllText(file).Replace("XXX-XX", "(the .jpg)"));

        A full program:

        using System.IO;
        namespace BLA {
        static class Program{
        static void Main(string[] files)
        {
        foreach(string file in files)
        File.WriteAllText(file, File.ReadAllText(file).Replace("XXX-XX", "(the .jpg)"));
        }}}

        Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

        R 1 Reply Last reply
        0
        • L Lutoslaw

          IMHO it's a single line of code:

          File.WriteAllText(file, File.ReadAllText(file).Replace("XXX-XX", "(the .jpg)"));

          A full program:

          using System.IO;
          namespace BLA {
          static class Program{
          static void Main(string[] files)
          {
          foreach(string file in files)
          File.WriteAllText(file, File.ReadAllText(file).Replace("XXX-XX", "(the .jpg)"));
          }}}

          Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.

          R Offline
          R Offline
          rowdykuttan
          wrote on last edited by
          #4

          It wont work since the.jpg has to be taken dynamically, its writing same file name for all XXX-XX

          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