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. appending "\" to a string

appending "\" to a string

Scheduled Pinned Locked Moved C#
question
10 Posts 6 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.
  • O Offline
    O Offline
    omlac
    wrote on last edited by
    #1

    How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.

    S M D O 5 Replies Last reply
    0
    • O omlac

      How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      Both of the first two work fine for me. 3rd one won't work because the \ sign is escaping the second " so you never actually close the quotes.

      Simon

      O 1 Reply Last reply
      0
      • O omlac

        How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.

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

        No you can't "abc\" is impossible...............

        “You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford

        1 Reply Last reply
        0
        • S Simon P Stevens

          Both of the first two work fine for me. 3rd one won't work because the \ sign is escaping the second " so you never actually close the quotes.

          Simon

          O Offline
          O Offline
          omlac
          wrote on last edited by
          #4

          Thank you for me the first two lines are adding two // but i want only 1 and the last one is an escape char.

          D A 2 Replies Last reply
          0
          • O omlac

            Thank you for me the first two lines are adding two // but i want only 1 and the last one is an escape char.

            D Offline
            D Offline
            Dan Neely
            wrote on last edited by
            #5

            Are the two \'s appearing in your output, or only in the debugger? The latter will of necessity show slashes used as escape characters when you look at a string. If it's the former, you need to provide a small program that reproduces this so we can see what you';re doing wrong.

            Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

            1 Reply Last reply
            0
            • O omlac

              Thank you for me the first two lines are adding two // but i want only 1 and the last one is an escape char.

              A Offline
              A Offline
              Ashfield
              wrote on last edited by
              #6

              Its because you are viewing it in the debugger I suspect. If you just hover the mouse over it it shows \\, but if you look at it using the text visualiser it will be correct. Its caught me out before...

              Bob Ashfield Consultants Ltd

              O 1 Reply Last reply
              0
              • O omlac

                How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.

                D Offline
                D Offline
                Daniel Grunwald
                wrote on last edited by
                #7

                \ is an escape character both in C# and RTF, so you'll have to escape it twice. rtf = rtf + @"\\"; or rtf = rtf + "\\\\";

                1 Reply Last reply
                0
                • A Ashfield

                  Its because you are viewing it in the debugger I suspect. If you just hover the mouse over it it shows \\, but if you look at it using the text visualiser it will be correct. Its caught me out before...

                  Bob Ashfield Consultants Ltd

                  O Offline
                  O Offline
                  omlac
                  wrote on last edited by
                  #8

                  Thank you all for your assistance Yes im viewing in the debugger, my problem is i want to search for a string and replace it with another but on the one im searching i want to append the "\" to it. like string str = @"\\"; string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\"", rep); rtf = rtf.Replace(MatchList[i].ToString() + str.Substring(1,1), rep); on rtf1 there is a "\" after the pgn. but MatchList[i].ToString() doesnt have the "\" and i cant include it in my search(regx) as well.

                  1 Reply Last reply
                  0
                  • O omlac

                    How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.

                    O Offline
                    O Offline
                    omlac
                    wrote on last edited by
                    #9

                    Thank you all for your assistance Yes im viewing in the debugger, my problem is i want to search for a string and replace it with another but on the one im searching i want to append the "\" to it. like string str = @"\\"; string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\"", rep); rtf = rtf.Replace(MatchList[i].ToString() + str.Substring(1,1), rep); on rtf1 there is a "\" after the pgn. but MatchList[i].ToString() doesnt have the "\" and i cant include it in my search(regx) as well.

                    1 Reply Last reply
                    0
                    • O omlac

                      How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.

                      O Offline
                      O Offline
                      omlac
                      wrote on last edited by
                      #10

                      rtf = "Testing Image Embading
                      \r\n
                      \r\nEmage Embabeded here\r\n" Regex exp = new Regex(@"img (alt=\.)?([^\.]+)\.png", RegexOptions.IgnoreCase); string InputText = rtf; MatchCollection MatchList = exp.Matches(InputText); Match FirstMatch = MatchList[0]; for (int i = 0; i < MatchList.Count; i++) { string str = @"\"; string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\"", rep); string strToReplace; //= MatchList[i].ToString(); //;+ str; //strToReplace = strToReplace.Substring(0, strToReplace.Length); strToReplace = string.Format(@"{0}\", MatchList[i].ToString()); rtf = rtf.Replace(strToReplace, rep); i hard corded rtf1 and it worked fine so what i want is for strToReplace to be equal to this string Web%20Cleint/Home%20Page/Images/Stop.png\" and im trying to achieve that by using this string string strToReplace; //= MatchList[i].ToString() + str; it appends 2 \\ and doesnt match the other string I hope this will help.

                      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