darkznet Posted July 26, 2003 Posted July 26, 2003 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 ?? Quote
Leaders dynamic_sysop Posted July 26, 2003 Leaders Posted July 26, 2003 if you know the phrase you are after then you can do this : 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 Quote
Moderators Robby Posted July 26, 2003 Moderators Posted July 26, 2003 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. 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 Quote Visit...Bassic Software
Leaders dynamic_sysop Posted July 26, 2003 Leaders Posted July 26, 2003 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 ) :-\ Quote
darkznet Posted July 26, 2003 Author Posted July 26, 2003 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 '''')'." Quote
Moderators Robby Posted July 26, 2003 Moderators Posted July 26, 2003 You need to include a second ' with each single quote... 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. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.