Get text from inside two symbols.
Ok, so lets say I have a textbox(Textbox1) and a button.
If the user inputs the text into the textbox: MsgBox "THIS IS MY MESSAGE"
I want that when the Button is pressed, only the text (THIS IS MY MESSAGE) is displayed.
Also, how would you do that if the user inputted into the textbox: MsgBox (THIS IS MY MESSAGE)
Using parenthesis instead of Quotation marks.
Re: Get text from inside two symbols.
Is this the only content of the textbox, one line among many, found anywhere in a longer text? Do you want to register syntax errors or are you content with any old delimiter? What is the ultimate aim here.
Re: Get text from inside two symbols.
It is in a one line textbox. If the user enters into the textbox: Msgbox "Any text here" I want to be able to take the text from the quotes, and put it in a variable for later use. I.e whatever text was in the quotation marks was put in the variable String1.
Re: Get text from inside two symbols.
Well, the very basic bones ...
If TextBox1.Text.ToLower.StartsWith("msgbox") Then
String1 = TextBox1.Text.Split(""""c)(1)
End If
Re: Get text from inside two symbols.
Thanks, this worked! Also, how would I go about doing this if I used parenthesis around the text I.e. Msgbox (Any text here) . Thanks! And is this possible in a multiline textbox?
Re: Get text from inside two symbols.
String1 = TextBox1.Text.Split({"(", ")"}, StringSplitOptions.None)(1)
Re: Get text from inside two symbols.
How would I do this for both scenarios (the text is surrounded by quoation marks or parenthesis) in a multiline textbox? Is that even possible?
Re: Get text from inside two symbols.
Maybe this will do it, dunno, am just adding a check for any of the scenarios using the 2 sample codes given above from dunfiddlin.
vb.net Code:
If TextBox1.Text.Contains("(") Then
If TextBox1.Text.ToLower.StartsWith("msgbox") Then String1 = TextBox1.Text.Split(""""c)(1)
ElseIf TextBox1.Text.Contains("""") Then
String1 = TextBox1.Text.Split({"(", ")"}, StringSplitOptions.None)(1)
End If