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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Passing special characters in a string

Passing special characters in a string

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

    I am having trouble passing a string that has special characters in it as an argument in a program. To be specific Method Signature: methodName(string) I need to pass the following string: QTextPrint("TestMessage") methodName("QTextPrint("TestMessage")"); Doesn't work methodName(""QTextPrint("TestMessage")""); Doesn't work methodName("QTextPrint\(\"TestMessage\"\)); Doesn't work methodName(@"QTextPrint\(\"TestMessage\"\)); Doesn't work Even attempting the same type of action in a stringbuilder doesnt work. Any ideas would be appreciated. Regards Bob Robey

    I M 2 Replies Last reply
    0
    • C CheckDude

      I am having trouble passing a string that has special characters in it as an argument in a program. To be specific Method Signature: methodName(string) I need to pass the following string: QTextPrint("TestMessage") methodName("QTextPrint("TestMessage")"); Doesn't work methodName(""QTextPrint("TestMessage")""); Doesn't work methodName("QTextPrint\(\"TestMessage\"\)); Doesn't work methodName(@"QTextPrint\(\"TestMessage\"\)); Doesn't work Even attempting the same type of action in a stringbuilder doesnt work. Any ideas would be appreciated. Regards Bob Robey

      I Offline
      I Offline
      IamJunk
      wrote on last edited by
      #2

      try this... methodName("QTextPrint(\"TestMessage\")"); I Hope this should work. If not give this a shot string param = "QTextPrint({0}TextMessage{1})"; param = string.Format(param, "\"", "\""); Hope this helps


      Regards, Sidhu IF YOU DON'T HAVE ANYTHING TO SAY, WELCOME TO THE CLUB Dotnet @ Work Where Dotnet works... My Blog

      1 Reply Last reply
      0
      • C CheckDude

        I am having trouble passing a string that has special characters in it as an argument in a program. To be specific Method Signature: methodName(string) I need to pass the following string: QTextPrint("TestMessage") methodName("QTextPrint("TestMessage")"); Doesn't work methodName(""QTextPrint("TestMessage")""); Doesn't work methodName("QTextPrint\(\"TestMessage\"\)); Doesn't work methodName(@"QTextPrint\(\"TestMessage\"\)); Doesn't work Even attempting the same type of action in a stringbuilder doesnt work. Any ideas would be appreciated. Regards Bob Robey

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        It's really quite simple: In C/C++/C# a string is delimited by " If you want to use " _inside_ a string you have to prefix this " (and only this one) with \ So #1 won't work because the first string ends before TestMessage, #2 won't work because you start with an empty string (""), #3 won't work because \( doesn't have to be escaped and #4 won't work because the @ will mess up all your \'s. Use methodName("QTextPrint(\"TestMessage\")"); This will work. Regards, mav

        C 1 Reply Last reply
        0
        • M mav northwind

          It's really quite simple: In C/C++/C# a string is delimited by " If you want to use " _inside_ a string you have to prefix this " (and only this one) with \ So #1 won't work because the first string ends before TestMessage, #2 won't work because you start with an empty string (""), #3 won't work because \( doesn't have to be escaped and #4 won't work because the @ will mess up all your \'s. Use methodName("QTextPrint(\"TestMessage\")"); This will work. Regards, mav

          C Offline
          C Offline
          CheckDude
          wrote on last edited by
          #4

          Thanks to both of you for your help. I selected the option of building the string using formatting since there were many segments that need to be concatenated. Problem Solved. Best Regards Bob Robey

          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