Results 1 to 13 of 13

Thread: [resolved] VB.NET: appending a text file of url's (at specific lines)

  1. #1

    Thread Starter
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Red face [resolved] VB.NET: appending a text file of url's (at specific lines)

    Ok lets say I have a text file called "google.txt", which contains 500 google links (going to different keywords or new stories etc.)
    What i want to do...is at line #50, #75, #100, #150...simply replace the existing "line" or google url in this list with http://finance.yahoo.com

    I know how to insert a string to a specific line # in a listbox (on the vb form) using the following code...
    Listbox1.Items.Insert(3, "http://finance.yahoo.com")
    ^ where 3 is the listbox line # i want to insert my text

    Can someone please show me how to do a similar thing to an "already existing" list in a text file?

    Thanks!!!
    Jenn
    Last edited by jalexander; Aug 24th, 2013 at 03:24 PM. Reason: [resolved]
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  2. #2

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: VB.NET: appending a text file of url's (at specific lines)

    Quote Originally Posted by jalexander View Post
    I know how to insert a string to a specific line # in a listbox (on the vb form) using the following code...
    Listbox1.Items.Insert(3, "http://finance.yahoo.com")
    ^ where 3 is the listbox line # i want to insert my text

    Can someone please show me how to do a similar thing to an "already existing" list in a text file?

    Thanks!!!
    Jenn
    maybe try loading the file into a list of string...
    Code:
    ' load file to list
    Dim lines As New List(Of String)(IO.File.ReadLines("file.txt"))
    ' insert a line
    lines.Insert(1, "Inserted this between line 0 and line 1.")
    ' replace a line.
    lines(5) = "replaced this line with this text!"
    ' save to file
    IO.File.WriteAllLines("file.txt", lines)
    Last edited by Edgemeal; Aug 24th, 2013 at 10:41 AM. Reason: simplify code

  4. #4

    Thread Starter
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Re: VB.NET: appending a text file of url's (at specific lines)

    Actually this is the easiest way to do it.....is.....

    Dim ss() As String
    ss = File.ReadAllLines("urls.txt")
    ss(3) = "http://finance.yahoo.com"
    ss(55) = "http://finance.yahoo.com"
    File.WriteAllLines("urls.txt", ss)


    But thanks guys....your suggestions will no doubt be helpful for other projects
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: VB.NET: appending a text file of url's (at specific lines)

    Quote Originally Posted by jalexander View Post
    Actually this is the easiest way to do it.....is.....

    Dim ss() As String
    ss = File.ReadAllLines("urls.txt")
    ss(3) = "http://finance.yahoo.com"
    ss(55) = "http://finance.yahoo.com"
    File.WriteAllLines("urls.txt", ss)


    But thanks guys....your suggestions will no doubt be helpful for other projects
    that's what ident told you to do

  6. #6
    Member
    Join Date
    Jun 2013
    Posts
    47

    Re: VB.NET: appending a text file of url's (at specific lines)

    I'm totally not surprised to read that people are starting to replace their google lines with yahoo ones from txt files. We all know this was meant to happen eventually it was only a matter of time.
    I think I'm gonna join the OP in the venture and exchange a couple of lines myself today.

  7. #7
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: VB.NET: appending a text file of url's (at specific lines)

    May I be the first to say eh?

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: VB.NET: appending a text file of url's (at specific lines)

    Quote Originally Posted by danniel64 View Post
    I'm totally not surprised to read that people are starting to replace their google lines with yahoo ones from txt files. We all know this was meant to happen eventually it was only a matter of time.
    I think I'm gonna join the OP in the venture and exchange a couple of lines myself today.
    Quote Originally Posted by ident View Post
    May I be the first to say eh?
    news to me too. just saw some news recently about how well google are doing.

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: VB.NET: appending a text file of url's (at specific lines)

    is this for currency conversions by any chance?
    the European Central Bank maintains an online XML file with all major currency rates

  10. #10
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: VB.NET: appending a text file of url's (at specific lines)

    News to me also. Can't remember the last time yahoo was even mentioned.

  11. #11

    Thread Starter
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Re: VB.NET: appending a text file of url's (at specific lines)

    @danniel64 huh?? are you talking about seo stuff or something?

    .paul. figured it out...as for how... I'll never know, maybe he is pyschic, considering it could have been links to literally anything, news, stocks, groups, i mean *** dude?? Anyways wow not knowing was just killing you guys wasn't it!

    And finally @ident, thanks for posting me to the simplest way buddy
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  12. #12
    Member
    Join Date
    Jun 2013
    Posts
    47

    Re: VB.NET: appending a text file of url's (at specific lines)

    Quote Originally Posted by jalexander View Post
    @danniel64 huh?? are you talking about seo stuff or something?
    Perhaps I am. It probably does involve SE adaptations being made.

    And I thought people were informed about recent events
    Code:
    http://www.cnbc.com/id/100980496
    Last edited by danniel64; Aug 24th, 2013 at 11:21 PM.

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [resolved] VB.NET: appending a text file of url's (at specific lines)

    Quote Originally Posted by http://www.cnbc.com/id/100980496
    However, the numbers do not include mobile usage and visitors are only counted once in a month, no matter how many times they return to the site.
    I use google hundreds of times in a month + that doesn't include my mobile usage

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