Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 ??

  • Leaders
Posted

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

  • Moderators
Posted

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

Visit...Bassic Software
  • Leaders
Posted

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 ) :-\

Posted

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 '''')'."

  • Moderators
Posted

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.

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...