locked
single double quote (to represent inches RRS feed

  • Question

  • I'm trying to create a string with a single double quote to represent inches.

    I've tried a couple of methods found on youtube however they both give me two double quote marks.

    Is there a 3rd method that may work?

    Line_Item_101_Description = ("xxx" + comboBox.SelectedItem + "\"\"" + " yyy" + "\r\n" + "zzz");

    Line_Item_101_Description = ("xxx" + comboBox.SelectedItem + '"' + " yyy" + "\r\n" + "zzz");

    tac


    tac

    Friday, September 7, 2018 6:39 PM

Answers

  • You need to escape the double quote inside the string as double quote is used for starting and ending of string literals.

    Do like this:

    string value = "xxx\"";     // xxx"

    In your example it would be:

    Line_Item_101_Description = ("xxx" + comboBox.SelectedItem + "\"" + " yyy" + "\r\n" + "zzz");

    Hope it helps.


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites



    • Edited by Ehsan Sajjad Saturday, September 8, 2018 8:53 AM
    • Marked as answer by Troy22222 Wednesday, September 12, 2018 1:56 PM
    Saturday, September 8, 2018 8:51 AM

All replies

  • You need to escape the double quote inside the string as double quote is used for starting and ending of string literals.

    Do like this:

    string value = "xxx\"";     // xxx"

    In your example it would be:

    Line_Item_101_Description = ("xxx" + comboBox.SelectedItem + "\"" + " yyy" + "\r\n" + "zzz");

    Hope it helps.


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites



    • Edited by Ehsan Sajjad Saturday, September 8, 2018 8:53 AM
    • Marked as answer by Troy22222 Wednesday, September 12, 2018 1:56 PM
    Saturday, September 8, 2018 8:51 AM
  • Hi Troy,

    >>I'm trying to create a string with a single double quote to represent inches....Is there a 3rd method that may work?

    Except the two methods as you said above, also you can insert the ASCII or Unicode character for a quotation mark. In Visual Basic, use the ASCII character (34). In Visual C#, use the Unicode character (\u0022). 

        string Line_Item_101_Description = ("xxx" + comboBox1.SelectedItem + '\u0022' + " yyy" + "\r\n" + "zzz");

    Refer to the following document for more details please:

    How to: Put Quotation Marks in a String (Windows Forms)

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Troy22222 Wednesday, September 12, 2018 1:56 PM
    • Unmarked as answer by Troy22222 Wednesday, September 12, 2018 1:56 PM
    Monday, September 10, 2018 3:23 AM
  • Stanly:

    Nothing seems to be working.

    I'm running C# VS2015

    I get    no matter what suggested method I use.

    I just need 36" (as in inches)


    tac

    Monday, September 10, 2018 9:33 PM
  • Greetings Troy.

    Your first attempt is on the right track.

    ine_Item_101_Description = ("xxx" + comboBox.SelectedItem + "\"\"" + " yyy" + "\r\n" + "zzz");

    But the rather obvious problem is that you have put \" twice, so of course you will get two quotes. Try putting it just once, like so.

    ine_Item_101_Description = ("xxx" + comboBox.SelectedItem + "\"" + " yyy" + "\r\n" + "zzz");

    Monday, September 10, 2018 11:35 PM
  • Stanly:

    Nothing seems to be working.

    I'm running C# VS2015

    I get    no matter what suggested method I use.

    I just need 36" (as in inches)


    tac

    Hi,

    I tested the code in Winform app:

            private void button2_Click(object sender, EventArgs e)
            {
                string Line_Item_101_Description = ("xxx" + comboBox1.SelectedItem + '\u0022' + " yyy" + "\r\n" + "zzz");
                richTextBox1.Text = Line_Item_101_Description;
            }

    And the result:

    @Ante, I think OP wants another method different with the two methods he mentioned above.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Stanly Fan Tuesday, September 11, 2018 1:48 AM
    Tuesday, September 11, 2018 1:48 AM
  • Stanly Fan,

    My understanding is that Troy believes the two methods he mentioned don't work. So I explained that the first one would work if he were to use it properly.

    And by the way, how do you create and insert those animations as in your post above?

    Tuesday, September 11, 2018 2:00 AM
  • Hi Ante,

    It is an app named Licecap, it can create a gif so that I can give OP a more vivid explanation.

    Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 11, 2018 2:30 AM
  • Thanks for that, SF. Unfortunately, I probably won't be allowed to install that app here at work, but I'll be able to use it at home.
    Tuesday, September 11, 2018 3:04 AM
  • Hi Ante,

    In fact, it is an app without install, just double click the .exe file to run, I share it to 1Drive, you can use it if you would like:

    https://1drv.ms/f/s!Aj5nhd5fHPkV3XXW1qxwr2qGYxn-

    Hope it can help you serve customers better.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 11, 2018 3:13 AM
  • Greetings SF.

    I downloaded the exe and gave it  try. I haven't fired it in anger yet (meaning, I haven't used it in a real post on these forums), but it looks like it will be very useful in future.

    Thanks again.

    Wednesday, September 12, 2018 3:58 AM
  • tried this again and it worked. Not sure why

    tac

    Wednesday, September 12, 2018 1:56 PM