|
-
Sep 17th, 2009, 08:18 AM
#1
Thread Starter
Fanatic Member
[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_
-
Sep 17th, 2009, 08:20 AM
#2
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
-
Sep 17th, 2009, 08:22 AM
#3
Thread Starter
Fanatic Member
Re: Some help with strings...
Yes, everything between <text> and </text>
-
Sep 17th, 2009, 08:46 AM
#4
Re: Some help with strings...
This link helps you to find out.
-
Sep 17th, 2009, 09:05 AM
#5
Frenzied Member
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
-
Sep 17th, 2009, 01:53 PM
#6
Thread Starter
Fanatic Member
Re: Some help with strings...
 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_
Last edited by Arve K.; Sep 17th, 2009 at 01:54 PM.
Reason: typo
-
Sep 17th, 2009, 01:55 PM
#7
Thread Starter
Fanatic Member
Re: Some help with strings...
 Originally Posted by Lightning
This link helps you to find out.
Ok, i will check that link later...
-
Sep 17th, 2009, 02:26 PM
#8
Hyperactive Member
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.
-
Sep 17th, 2009, 06:26 PM
#9
Thread Starter
Fanatic Member
Re: Some help with strings...
 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 
 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?
Last edited by Arve K.; Sep 17th, 2009 at 06:29 PM.
Reason: typo
-
Sep 17th, 2009, 08:31 PM
#10
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 17th, 2009, 09:05 PM
#11
Thread Starter
Fanatic Member
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|