-
Aug 23rd, 2013, 08:49 PM
#1
Thread Starter
Addicted Member
[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 |||
-
Aug 23rd, 2013, 09:17 PM
#2
Re: VB.NET: appending a text file of url's (at specific lines)
-
Aug 23rd, 2013, 09:48 PM
#3
Re: VB.NET: appending a text file of url's (at specific lines)
Originally Posted by jalexander
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
-
Aug 23rd, 2013, 10:19 PM
#4
Thread Starter
Addicted Member
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 |||
-
Aug 24th, 2013, 12:16 AM
#5
Re: VB.NET: appending a text file of url's (at specific lines)
Originally Posted by jalexander
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 24th, 2013, 04:17 AM
#6
Member
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.
-
Aug 24th, 2013, 04:31 AM
#7
Re: VB.NET: appending a text file of url's (at specific lines)
May I be the first to say eh?
-
Aug 24th, 2013, 05:02 AM
#8
Re: VB.NET: appending a text file of url's (at specific lines)
Originally Posted by danniel64
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.
Originally Posted by ident
May I be the first to say eh?
news to me too. just saw some news recently about how well google are doing.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 24th, 2013, 05:06 AM
#9
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 24th, 2013, 05:06 AM
#10
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.
-
Aug 24th, 2013, 03:22 PM
#11
Thread Starter
Addicted Member
-
Aug 24th, 2013, 11:17 PM
#12
Member
Re: VB.NET: appending a text file of url's (at specific lines)
Originally Posted by jalexander
@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.
-
Aug 24th, 2013, 11:43 PM
#13
Re: [resolved] VB.NET: appending a text file of url's (at specific lines)
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
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
|