473,378 Members | 1,542 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,378 software developers and data experts.

Streaming Text File: How to properly convert to integer

I have been working with one of my projects in asp.net. The user is to upload a text file. I read the file line by line, I first store the line in a string, and since the data is in a fix position, i just have to do a substring to it. I have to first validate the data in the text file before saving it to the database. I have used:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim ldt_file_data As DataTable
  3. Dim ldr_file_data As DataRow
  4. Dim lo_File As System.IO.StreamReader
  5. lo_File = System.IO.File.OpenText(import_path & file_name)
  6.  
  7. While Not (lo_File.EndOfStream)
  8.   ls_line = lo_File.ReadLine
  9.   ldr_file_data.Item("LNAME") = ls_line.Substring(0, 20).Trim
  10.   ldr_file_data.Item("FNAME") = ls_line.Substring(20, 20).Trim
  11.   ldr_file_data.Item("YEAR") = cint(ls_line.Substring(40, 4).Trim)
  12.   ldt_file_data.Rows.Add(ldr_file_data)
  13. End While
  14.  
  15.  
  16.  
I am retrieving the string just the way i wanted. The problem is that, when i try to use CINT to it, it returns a different value.

e.g. when i convert "2012" using CInt, it returns "&H7DC"

I think, it has something to do with encoding, i tried to use the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim lo_fs As FileStream
  3. Dim lo_File As StreamReader
  4. lo_fs = System.IO.File.Open(import_path & file_name, FileMode.OpenOrCreate)
  5. lo_File = New StreamReader(lo_fs, Encoding.UTF32)
  6.  
I have tried all sorts of encoding to no avail. Any help would be greatly appreciated. Thanks.
Jun 29 '12 #1

✓ answered by kadghar

great, you have the hexadecimal representation. Just change hex to dec and you're done.

1 1977
kadghar
1,295 Expert 1GB
great, you have the hexadecimal representation. Just change hex to dec and you're done.
Jul 3 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can...
5
by: Eric Sabine | last post by:
I have a web site where the user is able to download a file. I can't use an anchor tag because I don't want the user to see where the filename is coming from. Below is the code in which the user...
2
by: Troy | last post by:
Hi all, I want to export the contents of a datatable out to a web client and I am wondering what the best performance and maintanence concious method of doing this is. Would it be possible to...
0
by: Charles A. Lackman | last post by:
Hello, I am trying to have a desktop application receive a file from a web service. I am not sure how to do this, This is the Web Service Function. This is a webmethod that takes a file and...
9
by: Alex Buell | last post by:
I have a small text file which consist of the following data: ]] And the code I've written is as follows: ]] The trouble is, I can't work out why it goes into an infinite loop reading the...
1
by: abtet | last post by:
Hello people, I am new to php and have question on how to read text file and convert it to XML with php. . Can it be done if the text file contains text, image and also tables? please help...
10
by: kvazar | last post by:
Hello, I am new to php, and I need some help. I am trying to write a script for a web site. Text I need to display is in a .txt file, and I can't add breaks to it. I wrote a function that will...
2
by: progvar | last post by:
Hi! can any one help me by providing the method when i open any text file and convert into pdf format. I searched on the net and i got some code but i am not understanding this code and it also...
3
by: martinsmith160 | last post by:
Does anyone know how to read in data from a text file and initialize a variable to the string value that was read in from the file. E.g text file data: 100 200 300 I want to read in each...
3
by: Stacey Prahl | last post by:
Option Strict On Public Class frmBookPublishing ' Class Level Private Variables Private Shared _intSizeOfArray As Integer = 16 Private Shared _strWarehouseItem(_intSizeOfArray) As...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.