Results 1 to 11 of 11

Thread: [RESOLVED] Some help with strings...

  1. #1

    Thread Starter
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Resolved [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_

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    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
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3

    Thread Starter
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Re: Some help with strings...

    Yes, everything between <text> and </text>

  4. #4
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: Some help with strings...

    This link helps you to find out.
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  5. #5
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    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

  6. #6

    Thread Starter
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Re: Some help with strings...

    Quote Originally Posted by aashish_9601 View Post
    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

  7. #7

    Thread Starter
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Re: Some help with strings...

    Quote Originally Posted by Lightning View Post
    This link helps you to find out.
    Ok, i will check that link later...

  8. #8
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    407

    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.
    My Websites
    SharpMP3 - MP3 Design Articles www.sharpmp3.com
    Yobbers - Job Search www.yobbers.com
    Lets Trend - Methods For Riding Stock Trends www.letstrend.com

  9. #9

    Thread Starter
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Re: Some help with strings...

    Quote Originally Posted by jakkjakk View Post
    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 View Post
    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

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Some help with strings...

    try using regex:

    vb Code:
    1. Dim string_1 As String = "sometextblahblahdoodledooo<text>this is what i want</text>blahblahsomeothertext"
    2. Dim rx As New Regex("(?<=<text>).+?(?=</text>)")
    3. Dim string_2 As String = rx.Match(string_1).Value

    don't forget to import regex:

    vb Code:
    1. imports system.text.regularexpressions

  11. #11

    Thread Starter
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    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_
    Last edited by Arve K.; Sep 17th, 2009 at 09:14 PM.

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
  •  



Click Here to Expand Forum to Full Width