473,378 Members | 1,496 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.

How to Import Text file with Feild names in each line to Hashtable ?

1
Hi All,

I am very new in C# and am doing a test project. In my project i m using a text file which has records along with feild name in each line. How can i import the data in a Hashtable ??

Text File Example :

First_Name Joe
Last_Name Smith
Cell 9785466885
Email joesmith@xyz.com

First_Name Amanda
Last_Name Collin
Cell 4485965755
Email amandacollin@gstock.co

........ and so on...

i want to take just the values from each line and store in my hashtable.

Please Help !!

Thanks !
Veeky
Oct 12 '10 #1
3 2806
Curtis Rutland
3,256 Expert 2GB
What do you plan to key this hash table with? I'd personally suggest a Dictionary<string, string> instead of a HashTable, because of the type safety, it is much easier to work with.

You'll need to read the contents of the text file. My favorite tool for this is a StreamReader. There's an example of its use on the page. Read each line into a List<string>.

If you're trying to split each line around the space, then you'll need to .Split each string in your array.

After that, you'll have each entry. Just add them to the Dictionary/HashTable.
Oct 12 '10 #2
hi Curtis,

Thanks for the quick response... but is it possible for you to give me some example code... for doing this...

Thanks,
Oct 12 '10 #3
Curtis Rutland
3,256 Expert 2GB
All the example code you need is in the pages I linked. Most MSDN pages include example code.
Oct 12 '10 #4

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

Similar topics

4
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as...
2
by: Frank | last post by:
Hello, I have a fixed length text file that I want to import using c#. I want to read each line and break it apart. The problem is when I read a line, the data is not in a fixed position, so I...
3
by: Dave G | last post by:
I will shortly be receiving data in the form of a text file, like this: id: 123456 first name: Fred surname: Bloggs age: 26 and so on, for about 60 fields. Each line ends with a carriage...
0
by: erucevice | last post by:
I am trying to bcp a text file that is written out of a Java application. The text file has important order information that I need to bcp into a SQL Server 2000 database. The problem is that when...
3
by: tjuiowa | last post by:
Hi I am trying to import a text file into a MS Access database. The first 11 lines of the text file are in a different format, so i would like to skip those lines and start at line 12. is there...
1
by: prasampath | last post by:
Eny one knows how to import part of (specified location of text file, row location,text width,line no )of a text file to VB.Net.Pls
1
risk32
by: risk32 | last post by:
Hello. I'm trying to open a file for comparison to two (2) input box text values. ie: txtPassword.text + ";" + txtUsername.text must equal whats in a line in the UNPW (username password) text file...
2
by: Raman Pahwa | last post by:
i have a text file. I want to import it in table in sql 2005.that table has 8 fields.whn importing text file first 4 fields are in first line and next 2 in 2nd and rest 2 in last line. I want all 8...
1
by: Noorain | last post by:
sir my data are in text file. i want import text file in mysql data to use php script. please help me............. my text file is 1#AA#2,345.00 2#BB#850.00 3#CC#31,855.00
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
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?

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.