473,473 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

reading from a text file problem

today I tackled, for the first time, opening and reading from a text
file.

Following the example on the MSDN and declared a variable, strline as a
string and objstreamreader as a streamreader.

Basically I read in a line of a text file - this works fine.
I then read in another line. This works fine
However, the third time round I read character by character, until I
get to to the 40th character on the line, because this is the position
of some information that is a variable that I need. The problem is that
when using the read command (strline = objstreamreader.read) each
character is being given as a number (for example, when a space is read
in the string shows the number "32"). When I get to the correct
character I should get the string "1", instead I'm getting something
else. (A different number, but it's definately a translation of 1, not
the wrong character because all other characters on the line are
letters from a to z).

does anyone know why this happens and how I can re-translate the
number/code back into an alphanumeric version?

thanks,

Steve

Feb 19 '06 #1
2 1258
SteMc wrote:
today I tackled, for the first time, opening and reading from a text
file.

Following the example on the MSDN and declared a variable, strline as a
string and objstreamreader as a streamreader.

Basically I read in a line of a text file - this works fine.
I then read in another line. This works fine
However, the third time round I read character by character, until I
get to to the 40th character on the line, because this is the position
of some information that is a variable that I need. The problem is that
when using the read command (strline = objstreamreader.read) each
character is being given as a number (for example, when a space is read
in the string shows the number "32"). When I get to the correct
character I should get the string "1", instead I'm getting something
else. (A different number, but it's definately a translation of 1, not
the wrong character because all other characters on the line are
letters from a to z).

does anyone know why this happens and how I can re-translate the
number/code back into an alphanumeric version?

thanks,

Steve


When you read character by character you are getting the ASCII
representation of the character. If you do Chr(strline) on the one you
expect as "1" you will get your "1".

You may want to just read in the entire line and then do a substring on it.

strline = objstreamreader.readline
debug.writeline("My 40th Char is: " & strline.substring(39,1))

Chris
Feb 19 '06 #2
Ste,

The streamreader reads forever into a String (It can be in another format on
disk and than you can use the encoding). A String is in .Net forever in
Unicode format.

To get the value for that you can use the convert to Ascii which was in past
Asc and because that the characterset is now more wide better to use the
newer AscW("2"). The last instruction will give you "32".

In the otherway to get from a Unicode a Charachter it is ChrW(32) which will
give a 2.

I hope this helps,

Cor
Feb 20 '06 #3

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

Similar topics

1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
7
by: jamait | last post by:
Hi all, I m trying to read in a text file into a datatable... Not sure on how to split up the information though, regex or substrings...? sample: Col1 Col2 ...
8
by: Phil Slater | last post by:
I'm trying to process a collection of text files, reading word by word. The program run hangs whenever it encounters a word with an accented letter (like rôle or passé) - ie something that's not a...
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
1
by: Need Helps | last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
10
by: T Cordon | last post by:
I am using a StreamReader to read text from an HTML file and display it as part of a page in a Label Control. Buy it is not displaying characters as: ñ, ó, ú, etc. Please Help. Thanks
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
2
by: Mad Scientist Jr | last post by:
i'm trying to read a file byte by byte (and later alter the data and write it to a 2nd file byte by byte) and running into a problem where it seems to keep reading the same byte over and over again...
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.