locked
Quotes in a string RRS feed

  • Question

  •  

    I have what is probably a relatively simple problem but it is vexing me none the less. I am writing a simple program to send net send messages. The syntax of net send requires quotes. I am using the following.

     

     

    Shell("c:\windows\system32\net.exe send " & Sendto & " & RichTextBox1.Text & ")

     

    That returns a nice message box that says &richtextbox1.text&

    I know it is a quote problem but I don't know what to do. Help?

    Friday, February 8, 2008 3:11 PM

Answers

  • First off you should use Process.Start() instead of the VB6 style Shell function (unless you are using VB6 in which case you are asking for help in the wrong place).

     

    When you need to include quotes in a string, you need to double them up. One set of quotes back to back in a string equals one actual quote. It also makes things a bit easier to read as the developer if you use the string.format() method to format the string with your variables. Here is a small example:

     

    This creates a string called LaunchString which puts your SendTo and RichTextBox1.Text variables into the string before you call process.start() to actually execute the command. Note the double quotes around the {1} param, this will give you literal quotes in the string.

     

    Code Snippet

    Dim LaunchString As String = String.Format("c:\windows\system32\net.exe send {0} ""{1}""", SendTo, RichTextBox1.Text)

    System.Diagnostics.Process.Start(LaunchString)

     

     

    Friday, February 8, 2008 3:20 PM
    Moderator

All replies

  • First off you should use Process.Start() instead of the VB6 style Shell function (unless you are using VB6 in which case you are asking for help in the wrong place).

     

    When you need to include quotes in a string, you need to double them up. One set of quotes back to back in a string equals one actual quote. It also makes things a bit easier to read as the developer if you use the string.format() method to format the string with your variables. Here is a small example:

     

    This creates a string called LaunchString which puts your SendTo and RichTextBox1.Text variables into the string before you call process.start() to actually execute the command. Note the double quotes around the {1} param, this will give you literal quotes in the string.

     

    Code Snippet

    Dim LaunchString As String = String.Format("c:\windows\system32\net.exe send {0} ""{1}""", SendTo, RichTextBox1.Text)

    System.Diagnostics.Process.Start(LaunchString)

     

     

    Friday, February 8, 2008 3:20 PM
    Moderator
  • I'm not using VB6, I'm not a developer by trade I just dabble in it when the need presents. That is the way I learned it the first time and I guess I just haven't kept up.

     

    Thanks.

    Friday, February 8, 2008 3:58 PM