Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » CSV file
CSV file [message #43315] Sun, 29 June 2014 12:56 Go to next message
idkfa46 is currently offline  idkfa46
Messages: 155
Registered: December 2011
Experienced Member
Hi,
I have a CSV file with a lot of informations about cities. How can i read the file and fill my DropList with all city names?

Here is en example of CVS: (city names in red)
ANDEZENO,(TO),4,0,7.869,45.037,001009,001,01,[color=red]Torino[/color],PIEMONTE
ANDRATE,(TO),4,0,7.875,45.527,001010,001,01,[color=red]Torino[/color],PIEMONTE
ANGROGNA,(TO),2,0,7.225,44.843,001011,001,01,[color=red]Torino[/color],PIEMONTE
ARIGNANO,(TO),4,0,7.902,45.04,001012,001,01,[color=red]Torino[/color],PIEMONTE
AVIGLIANA,(TO),3,0,7.397,45.079,001013,001,01,[color=red]Torino[/color],PIEMONTE
AZEGLIO,(TO),4,0,7.994,45.424,001014,001,01,[color=red]Torino[/color],PIEMONTE
BAIRO,(TO),4,0,7.755,45.386,001015,001,01,[color=red]Torino[/color],PIEMONTE
...


I have found that functions in utilities:
- String CsvString(const String& text)
- Vector<String> GetCsvLine(Stream& s, int separator, byte charset)
but I'm in trouble trying to use them...

May I have an example?

Regards,
Matteo
Re: CSV file [message #43319 is a reply to message #43315] Sun, 29 June 2014 22:46 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
idkfa46 wrote on Sun, 29 June 2014 12:56
Hi,
I have a CSV file with a lot of informations about cities. How can i read the file and fill my DropList with all city names?

Here is en example of CVS: (city names in red)
ANDEZENO,(TO),4,0,7.869,45.037,001009,001,01,[color=red]Torino[/color],PIEMONTE
ANDRATE,(TO),4,0,7.875,45.527,001010,001,01,[color=red]Torino[/color],PIEMONTE
ANGROGNA,(TO),2,0,7.225,44.843,001011,001,01,[color=red]Torino[/color],PIEMONTE
ARIGNANO,(TO),4,0,7.902,45.04,001012,001,01,[color=red]Torino[/color],PIEMONTE
AVIGLIANA,(TO),3,0,7.397,45.079,001013,001,01,[color=red]Torino[/color],PIEMONTE
AZEGLIO,(TO),4,0,7.994,45.424,001014,001,01,[color=red]Torino[/color],PIEMONTE
BAIRO,(TO),4,0,7.755,45.386,001015,001,01,[color=red]Torino[/color],PIEMONTE
...




Ciao,

I use Split() to separate a String/row/record in several fields and get what I like.
For example:
FileIn in(filedbname);
while(!in.IsEof()) 
{
	String line = in.GetLine();
	Vector<String> fields = Split(line, ","); // , in your case
        String city = fields[0];
        String prov = fields[1];
        //...
        String region = fields[10];
}

I hope this is useful for you.
Luigi

[Updated on: Sun, 29 June 2014 22:48]

Report message to a moderator

Re: CSV file [message #43322 is a reply to message #43319] Mon, 30 June 2014 10:09 Go to previous messageGo to next message
deep is currently offline  deep
Messages: 263
Registered: July 2011
Location: Bangalore
Experienced Member
Check this link

http://www.ultimatepp.org/forums/index.php?t=msg&goto=33 679&&srch=csv+parse#msg_33679


Warm Regards

Deepak
Re: CSV file [message #43338 is a reply to message #43315] Tue, 01 July 2014 16:01 Go to previous messageGo to next message
idkfa46 is currently offline  idkfa46
Messages: 155
Registered: December 2011
Experienced Member
thanks...
I'm using Split() now and it's working fine!

M
Re: CSV file [message #43342 is a reply to message #43338] Thu, 03 July 2014 09:27 Go to previous message
deep is currently offline  deep
Messages: 263
Registered: July 2011
Location: Bangalore
Experienced Member
Hi,

If you have ',' in the String "Somthing, Something", Split() will not work properly.

Code from the link will work in all cases.


Warm Regards

Deepak
Previous Topic: EXCEPTION_ACCESS_VIOLATION
Next Topic: How to position dialog in relation to parent window
Goto Forum:
  


Current Time: Thu Mar 28 23:07:17 CET 2024

Total time taken to generate the page: 0.01677 seconds