473,322 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

assigning file contents to a string

For purposes of sending the contents of a file to a function that requires a
string, I am trying to find a way to read a file to a string variable & pass
it along.

For example, if the file text.txt contained "this is a test" I couldn't just
do this:
strVar = "text.txt"
because the string variable would obviously represent just the filename &
not it's contents.

I am sorry if this is very simple, but of course I'm new to VB (& ASP) and
any suggestions would be great.
Thanks.

Nov 20 '05 #1
3 974
* "Mark" <me@here.com> scripsit:
For purposes of sending the contents of a file to a function that requires a
string, I am trying to find a way to read a file to a string variable & pass
it along.

For example, if the file text.txt contained "this is a test" I couldn't just
do this:
strVar = "text.txt"
because the string variable would obviously represent just the filename &
not it's contents.


\\\
Dim sr As New System.IO.StreamReader("C:\bla.txt")
Dim s As String = sr.ReadToEnd()
sr.Close()
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
"Mark" <me@here.com> schrieb
For purposes of sending the contents of a file to a function that
requires a string, I am trying to find a way to read a file to a
string variable & pass it along.

For example, if the file text.txt contained "this is a test" I
couldn't just do this:
strVar = "text.txt"
because the string variable would obviously represent just the
filename & not it's contents.

I am sorry if this is very simple, but of course I'm new to VB (&
ASP) and any suggestions would be great.
Thanks.

http://msdn.microsoft.com/library/en...Processing.asp
http://msdn.microsoft.com/library/en...kingwithio.asp
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Try
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New StreamReader("TestFile.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(Line)
Loop Until line Is Nothing
sr.Close()
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try

"Mark" <me@here.com> wrote in message
news:el**************@TK2MSFTNGP11.phx.gbl...
For purposes of sending the contents of a file to a function that requires a string, I am trying to find a way to read a file to a string variable & pass it along.

For example, if the file text.txt contained "this is a test" I couldn't just do this:
strVar = "text.txt"
because the string variable would obviously represent just the filename &
not it's contents.

I am sorry if this is very simple, but of course I'm new to VB (& ASP) and
any suggestions would be great.
Thanks.

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: gtz669 | last post by:
I have a class which I am using for data stroage. I declare an instance of that class in my main class which is running my java applet. I Iassign it a value in the init () function and it works...
5
by: rxl124 | last post by:
Hi, quick question, how would you assign a contents to file in perl i was thinking $filename=`echo newvalue > filename`;
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
11
by: Skc | last post by:
I have a .txt which has been exported as a .csv from an external source. What i need to do is to import this into SQL2000 (into a table) but I need to do special things on the data: 1. I need to...
10
by: Steve Pope | last post by:
The first of the following functions compiles, the second gives what I think is a spurious error: "cannot convert `const char' to `char *' in assignment". void foo(int m) { char *str; if (m...
2
by: Patrick | last post by:
Hi All, I have numerous files that look like the chunk below. From the date and time I calculate a year day value. For the example that value is 148.67721064815 I'm not an expert yet at...
15
by: Gan Quan | last post by:
I'm writing a c++ program that has many (100+) threads read/write files simultaneously. It works well if not considering the efficiency. The file i/o seems to be the bottleneck. This is my code...
45
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
4
by: Mr Gray | last post by:
Hi Guys, My requirement is to scan an FTP directory for the presence of 4 files and if a specific file exists I can begin to GET those files, read the contents and save the contents into an SQL...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.