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 replace text in this situation?

How to replace text in this situation?

Scheduled Pinned Locked Moved C#
questiontutorial
3 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.
  • T Offline
    T Offline
    turbosupramk3
    wrote on last edited by
    #1

    Using the code below, I am trying to find the text

    but when I view what my program is seeing, it is actually seeing

    <add key=\"GetListDefaultResultSize\" value=\"6500\" />

    How do I adjust for the escape characters that are added before the quotes when my code does a File.ReadAllText?

    string allFileText = File.ReadAllText(networkFilePath);
    if (allFileText.Contains(replacementLine))
    {
    lvwAppendFiles.Items.Add(networkFilePath + " contains " + replacementLine);
    }
    else
    {
    lvwAppendFiles.Items.Add(networkFilePath + " does NOT contain " + replacementLine);
    }

    L M 2 Replies Last reply
    0
    • T turbosupramk3

      Using the code below, I am trying to find the text

      but when I view what my program is seeing, it is actually seeing

      <add key=\"GetListDefaultResultSize\" value=\"6500\" />

      How do I adjust for the escape characters that are added before the quotes when my code does a File.ReadAllText?

      string allFileText = File.ReadAllText(networkFilePath);
      if (allFileText.Contains(replacementLine))
      {
      lvwAppendFiles.Items.Add(networkFilePath + " contains " + replacementLine);
      }
      else
      {
      lvwAppendFiles.Items.Add(networkFilePath + " does NOT contain " + replacementLine);
      }

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

      Since it looks like XML, I would consider using the

      System.Xml and System.Xml.Linq

      classes instead of trying to interpret the input myself.

      1 Reply Last reply
      0
      • T turbosupramk3

        Using the code below, I am trying to find the text

        but when I view what my program is seeing, it is actually seeing

        <add key=\"GetListDefaultResultSize\" value=\"6500\" />

        How do I adjust for the escape characters that are added before the quotes when my code does a File.ReadAllText?

        string allFileText = File.ReadAllText(networkFilePath);
        if (allFileText.Contains(replacementLine))
        {
        lvwAppendFiles.Items.Add(networkFilePath + " contains " + replacementLine);
        }
        else
        {
        lvwAppendFiles.Items.Add(networkFilePath + " does NOT contain " + replacementLine);
        }

        M Offline
        M Offline
        Matt T Heffron
        wrote on last edited by
        #3

        If you are looking at the string in the debugger, it is the debugger that is adding the escape characters to what it is displaying, they aren't actually in the string. The easy way to verify this is to check the Length of the string. It should not include the escape characters in the count.

        "Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed." - G.K. Chesterton

        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