Text in quotes?

jigax

Active member
Joined
Aug 17, 2006
Messages
43
Programming Experience
Beginner
Hello,

How could I get text inside quote?

j1[1] = "EXTRACTME";

I only want to get the word EXTRACTME.

Thank you.
 
I managed to get what I wanted doing this.

line = Replace(line, ";", "")
writer.Write(Trim(Mid(line, 9)))

Please correct me if theres a better way of doing this.
 
I managed to get what I wanted doing this.

line = Replace(line, ";", "")
writer.Write(Trim(Mid(line, 9)))

Please correct me if theres a better way of doing this.

What if the line starts "j1[10]" - your value of 9 is then wrong.

Judging by the code you posted, that's how it used to be done in VB6. Assumine sLine holds the text as discussed above, here's two different ways to do it in VB.NET :-

VB.NET:
        Dim sLine As String = ""
        sLine = String.Format("j1[10] = {0}EXTRACTME{0};", Microsoft.VisualBasic.ControlChars.Quote)
        sLine = sLine.Remove(0, sLine.IndexOf(Microsoft.VisualBasic.ControlChars.Quote) + 1) 'strip the first part
        sLine = sLine.Remove(sLine.IndexOf(Microsoft.VisualBasic.ControlChars.Quote)) 'strip the last part
        MessageBox.Show(sLine) 'show what is left

and also

VB.NET:
        Dim sLine As String = ""
        sLine = String.Format("j1[10] = {0}EXTRACTME{0};", Microsoft.VisualBasic.ControlChars.Quote)
        Dim sPartsOfLine() As String = sLine.Split(Microsoft.VisualBasic.ControlChars.Quote) 'break the line into three parts
        MessageBox.Show(sPartsOfLine(1)) 'you want the middle part
 
You also have regular expressions:
VB.NET:
Dim input As String = "j1[1] = ""EXTRACTME"";"
Dim pattern As String = """(?<quote>.*?)"""
Dim quoted As String = Regex.Match(input, pattern).Groups("quote").Value
 
Back
Top