LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-27-2005, 11:55 AM   #1
mrobertson
Member
 
Registered: May 2005
Posts: 275

Rep: Reputation: 30
separating a comma delimited line


I have a text file that looks like this:

1033, 23.98, .1234, .5678

I am going to need to read this line. 1033 needs to go into "its text box" and so on.

Can anybody help me as to how this would be done?
 
Old 07-27-2005, 12:15 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
And you are using what programming language? On what platform?
 
Old 07-27-2005, 12:52 PM   #3
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I am using vb.net
 
Old 07-27-2005, 02:47 PM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
You could try using the Excel COM objects to read in CSV files, but that is probably overkill, and if you have a large CSV file, very slow...

If you are never going to have quoted strings in the CSV file a simple string split on the comma would work.

In C# that would be something like:

Code:
string s = "1033, 23.98, .1234, .5678";

string[] fields = s.Split(',');
I'm assuming that the VB.Net and C#.Net strings have pretty similar methods and properties here, so you should be able to translate that into VB.Net without too much trouble. You may also need to trim whitespace off of each element in the array before using it using the Trim() method.
 
Old 07-27-2005, 02:49 PM   #5
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
thanks alot for your help!. It worked perfectly. I have another thread posted that reads as follows:

I am capable of being able to write to a text file. I use the following code in my application:



Code:
FileOpen(10, "C:\Documents and Settings\alogue\Desktop\Coil PDI\PDI.txt", OpenMode.Output)
            PrintLine(10, txtgradecode.Text, ",", txtwidth.Text, ",", txthbgauge.Text, ",", txttargetgauge.Text)
            FileClose(10)

This will write whatever I type into those text boxes to a text file. However, If I write something new in the text boxes it writes over my last entry into the text box. Is there anyway to append to a text file and not have to write over your previous work?

Any advice here?
 
Old 07-27-2005, 02:54 PM   #6
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
I believe (haven't used VB.net) that there is an OpenMode.Append instead of OpenMode.Output
 
Old 07-27-2005, 02:55 PM   #7
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
how do you use it?
 
Old 07-27-2005, 02:56 PM   #8
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Where your code uses OpenMode.Ouput, use OpenMode.Append.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
separating strings cxel91a Programming 3 05-01-2004 07:54 PM
delimited and if nstanley Linux - Newbie 11 03-01-2004 10:35 AM
Comma-Delimited Website Filenames Apocalypse General 1 11-09-2003 10:05 AM
separating words cxel91a Programming 14 04-29-2003 02:05 PM
comma delimited file cdragon Programming 5 06-21-2002 08:55 PM


All times are GMT -5. The time now is 04:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration