Results 1 to 10 of 10

Thread: [RESOLVED] Between

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Resolved [RESOLVED] Between

    Hi, is there a way to show the text that is between something?
    like this.
    if i have this code
    Image Code:
    1. <input class="text" onClick='highlight(this);' value="[url=http://www.imgupp.com/uploads/pubtrick694407.jpg][/url]"
    and i would like to show the text that are between [url and jpg] means http://www.imgupp.com/uploads/pubtrick694407

    is there a way to do this?

    tanks

  2. #2
    Hyperactive Member
    Join Date
    Aug 2003
    Location
    Wigan, UK
    Posts
    291

    Re: Between

    You can use IndexOf to find url= and .jpg then substring
    Code:
    'find url= and add 4 because we want the string after it
            Dim start As Integer = yourstring.IndexOf("url=") + 4
    
            'find .jpg
            Dim finish As Integer = yourstring.IndexOf(".jpg")
    
            'show the string between the index's found
            MessageBox.Show(yourstring.Substring(start, finish - start))

  3. #3

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Between

    when u say yourstring u mean the .jpg ... ?
    Last edited by met0555; Apr 22nd, 2007 at 04:04 PM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Between

    He means the string that you want to get the substring of. "yourstring" means the string that you're using, i.e. your string.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Between

    Well, i've tried it as i understand it . And i've got this error
    Code:
    Length cannot be less than zero.
    Parameter name: length

    vb Code:
    1. Dim mystring As String
    2.         mystring = "mystring"
    3.         'find url= and add 4 because we want the string after it
    4.         Dim start As Integer = mystring.IndexOf("url=") + 4
    5.  
    6.         'find .jpg
    7.         Dim finish As Integer = mystring.IndexOf(".jpg")
    8.  
    9.         'show the string between the index's found
    10.         MessageBox.Show(mystring.Substring(start, finish - start))
    Last edited by met0555; Apr 23rd, 2007 at 02:57 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Between

    Do you know what argument of what method that error message is talking about? What line did it occur on? What method on that line has an parameter named "length"? What is the value of that parameter when you call the method? How is that value calculated?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Between

    i know it's talking about
    vb Code:
    1. MessageBox.Show(mystring.Substring(start, finish - start))

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Between

    So what about my other questions? This is how you solve problems. There isn't much code on that line so it shouldn't be too hard to work out which is the "length" parameter. Once you know that then you can check it's value. The error message says that it's less than zero and it's not allowed to be. How was it calculated? How did it get to be less than zero? Is it a data error or a logic error?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Between

    ok, i get what it was wrong, now my problem is i'm trying to select a text from an .html ("C:\tempsysfile.html") file, how do i do that?

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Between

    HTML files are just plain text. You read them the same way(s) as any other text file.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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