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

Code refactoring: Reading string data from file and converting the data type

440 256MB
Hi ,

When ever we read any data from file ,we read as a single line string ,and we convert the respective field data available in that string based on the data type ( say int,float ).

Please suggest me which is the best way of handling the file data.

I- Method:
----------------

Store as single line string data's(upto end of file ) in a list and make use of this string list for the entire application.

When we required that single line data, which is having different data types,we convert it and get that details and make use of these data types in our application when and as required

In a nut shell,while reading the data we are storing as string data,when it is required in the application to do geometric operation ,we convert the data into int /float from the string at that location

II- Method:
---------------

Traverse the singleline data and convert the string data into the respective datatypes and store in a variable (say list).

In a nut shell,while reading the data itself ,we are converting the respective data types and storing it,instead of keeping the data in string format


Store as single line string data for the entire application and whenever you required that single line data,in different data types,you convert it and get the deatils and make use of these data types in your application.

Thanks
PSB
Apr 3 '07 #1
3 3231
bvdet
2,851 Expert Mod 2GB
Hi ,

When ever we read any data from file ,we read as a single line string ,and we convert the respective field data available in that string based on the data type ( say int,float ).

Please suggest me which is the best way of handling the file data.

I- Method:
----------------

Store as single line string data's(upto end of file ) in a list and make use of this string list for the entire application.

When we required that single line data, which is having different data types,we convert it and get that details and make use of these data types in our application when and as required

In a nut shell,while reading the data we are storing as string data,when it is required in the application to do geometric operation ,we convert the data into int /float from the string at that location

II- Method:
---------------

Traverse the singleline data and convert the string data into the respective datatypes and store in a variable (say list).

In a nut shell,while reading the data itself ,we are converting the respective data types and storing it,instead of keeping the data in string format


Store as single line string data for the entire application and whenever you required that single line data,in different data types,you convert it and get the deatils and make use of these data types in your application.

Thanks
PSB
I would create a dictionary, set or list from the file data with the values converted. That is not required, but it is my preference. I want to do the work necessary on import to make the data readily available.
Apr 3 '07 #2
psbasha
440 256MB
I would create a dictionary, set or list from the file data with the values converted. That is not required, but it is my preference. I want to do the work necessary on import to make the data readily available.

Most of the experienced developers follow the same approach ,and I hope it is a best practice also.

But performance wise which is best way of doing.

Prepare the data in the begining itself by converting ,so that it will be easy for us to do any data manipulation.And no need to think in the middle of the application development ,whether the data is string or int or etc. we will know that our data has converted in the correct format.

Otherwise we will get confused when we get different results,and we have to check for each value,whether it is string or other datatype,with "print" out statements.

Once I faced the problem .when I am passing the ID as "int" to the method.Thinking that I have converted the ID from 'string' to 'int'.When i was struggling for longer time, and after anlayizing the data I came to know that one data type is in "string" format and the input data what i am passing is "int" format


Thanks
PSB
Apr 3 '07 #3
psbasha
440 256MB
But performance wise which is the best way of doing.??

Can anybody suggest on this

-PSB
Apr 3 '07 #4

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

Similar topics

12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
0
by: Eric Lilja | last post by:
Hello, I have a text file that contains a number of entries describing a recipe. Each entry consists of a number of strings. Here's an example file with only one entry (recipe): Name=Maple Quill...
2
by: David Scemama | last post by:
Hi, I'm developing an application that reads data from a file. The data has been encoded using code page 850. I use the FileOpen function to open the file and the FileGet function to read the...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
82
by: Edward Elliott | last post by:
This is just anecdotal, but I still find it interesting. Take it for what it's worth. I'm interested in hearing others' perspectives, just please don't turn this into a pissing contest. I'm in...
5
by: psbasha | last post by:
Hi, When we read any file data format in any programming language.It will be read as as a string or characters.Later based on the type of data ,we will convert to the respective datatype by type...
6
by: Richard Maher | last post by:
Hi, Now that I am aware that JS on a page in Frame A can directly call a function on a page in Frame B, I no longer have to continue with my frameB.location.reload() fudge in order to get some...
4
by: donpro | last post by:
Hi, I've created a table where the header columns link to an AJAX function which calls a PHP file and returns content - the purpose is to sort the table on the heading. The code snippet is:...
1
by: dwaterpolo | last post by:
Hi Everyone, I am trying to read two text files swY40p10t3ctw45.col.txt and solution.txt and compare them, the first text file has a bunch of values listed like: y y y y y y y
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.