[RESOLVED] Some help with strings...
Hi,
I have two strings:
Code:
Dim string_1 as String = "sometextblahblahdoodledooo<text>this is what i want</text>blahblahsomeothertext"
Dim string_2 as String
What I want is to put the text "this is what i want" into string_2.
Can someone please help me with this?? :)
_powerade_
Re: Some help with strings...
How do you know what needs to be in string_2? Is it everything between <text> and </text>
or
or
Re: Some help with strings...
Yes, everything between <text> and </text> :)
Re: Some help with strings...
This link helps you to find out.
Re: Some help with strings...
does the word "<text>" exists in string1 or did you just used it to indicate the position of string2 to be inserted
Re: Some help with strings...
Quote:
Originally Posted by
aashish_9601
does the word "<text>" exists in string1 or did you just used it to indicate the position of string2 to be inserted
Yes, it exists in the string, it's like this:
<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Google</title><script>window.google=...
but instead of <title> it is <text>... :)
_powerade_
Re: Some help with strings...
Quote:
Originally Posted by
Lightning
This
link helps you to find out.
Ok, i will check that link later...
Re: Some help with strings...
all you gotta do is do a search for the first <text> then do another search for the next <text> then take the string between the > of the first <text> and the < of the next text. You'll get your substring. easy. Scrappers work this way all the time.
Re: Some help with strings...
Quote:
Originally Posted by
jakkjakk
all you gotta do is do a search for the first <text> then do another search for the next <text> then take the string between the > of the first <text> and the < of the next text. You'll get your substring. easy. Scrappers work this way all the time.
I know, but unfortunately pseudocode isn't helping me at all :( :(
Quote:
Originally Posted by
Lightning
This
link helps you to find out.
This is what I got so far:
Code:
Dim string_1 As String = "blahblahblah<text>Get me!</text>blahblahblah"
Dim string_2 As String = string_1.Remove(0, string_1.IndexOf("<text>") + 6)
string_2 = string_2.Remove(string_2.IndexOf("</text>"), 0) '<-- What do I put here??? I need to remove rest of the unuseful text...
I got rid of the left side of string, but what about the right? I suppose I should use .Length in some way, but how do I know the correct length?
Re: Some help with strings...
try using regex:
vb Code:
Dim string_1 As String = "sometextblahblahdoodledooo<text>this is what i want</text>blahblahsomeothertext"
Dim rx As New Regex("(?<=<text>).+?(?=</text>)")
Dim string_2 As String = rx.Match(string_1).Value
don't forget to import regex:
vb Code:
imports system.text.regularexpressions
Re: Some help with strings...
Thank you a lot :)
I have heard people talk about regex and what it can do, but it is waaay to complex for me:)... But hey, it worked, so thank you again :)
_powerade_