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. Regular expressions in C#

Regular expressions in C#

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

    Hi, I have an application where users can do many find/replace operations, including regexes. The problem is that if the user wants to replace something with a carriage return/newline and enter \r\n it literally replaces with "\r\n", however if I try the same thing but in the code, and specify a regex to replace something with \r\n it does replace with a carriage return/newline. Otherwise the regex works properly, for example the user can find a carriage return/newline with \r\n and they can replace with $1 for example, but it just doesn't work when you try and replace with \r\n. thanks for any help!

    R 1 Reply Last reply
    0
    • M Martin23

      Hi, I have an application where users can do many find/replace operations, including regexes. The problem is that if the user wants to replace something with a carriage return/newline and enter \r\n it literally replaces with "\r\n", however if I try the same thing but in the code, and specify a regex to replace something with \r\n it does replace with a carriage return/newline. Otherwise the regex works properly, for example the user can find a carriage return/newline with \r\n and they can replace with $1 for example, but it just doesn't work when you try and replace with \r\n. thanks for any help!

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      If the user types this into the textbox it's like you would define the string like the following: string s = @"\r\n"; or string s = "\\r\\n"; You could replace it manually within your code: string s = s.Replace(@"\r, "\r).Replace(@"\n", "\n");

      M 1 Reply Last reply
      0
      • R Robert Rohde

        If the user types this into the textbox it's like you would define the string like the following: string s = @"\r\n"; or string s = "\\r\\n"; You could replace it manually within your code: string s = s.Replace(@"\r, "\r).Replace(@"\n", "\n");

        M Offline
        M Offline
        Martin23
        wrote on last edited by
        #3

        thanks, worked great!

        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