Getting Necessary Information

darkznet

Newcomer
Joined
Jul 25, 2003
Messages
4
Lets say i have a string assign to a variable.

x = "hello . How are you there**I am Leanord**This world is beautiful"

How can i just extract a particular phrase only?? which is just "I am Leanord" and stored it in a variable ??
 
if you know the phrase you are after then you can do this :
Visual Basic:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As String = "hello . How are you there I am Leanord This world is beautiful"
        Dim i As Integer = Len("I am Leanord")
        Dim s As String = x.Substring(InStr(x, "I") - 1, i)

        MessageBox.Show(s)

    End Sub
 
Darkznet, It seems that you may not know in advance which sentence you want to extract, or even what that sentence may be, is this correct?
Anyway, try this.
Visual Basic:
        Dim x As String = "hello . How are you there*I am Leanord*This world is beautiful"
        Dim a() As String = x.Split("*"c)
        Dim i As Integer

        For i = 0 To a.GetUpperBound(0)
            MessageBox.Show(a(i))
        Next
    End Sub
 
i get the feeling that the * 's aint supposed to be there , but are just there to show which bit they want to extract eg:
"hello . How are you there**I am Leanord**This world is beautiful"

would be :
"hello . How are you there I am Leanord This world is beautiful"

and they want to find "I am Leanord" from the line ( but the line doesnt actually hold any * 's ) :-\
 
Thanks for the sample. Now i have another problem.

x = "hello. How're you there ? "

Everytime when i try to insert the string into the database, it gave me the following error. I know the error is caused by " ' " in the string. Any way i can solved this problem ???

" Syntax error in string in query expression '''')'."
 
You need to include a second ' with each single quote...
Visual Basic:
        Dim x As String = "hello. How're you there ? "
        Dim s As String = x.Replace("'", "''")
        MessageBox.Show(s)

'Don't worry it will go into the DB as one single quote.
 
Back
Top