8 Replies - 539 Views - Last Post: 09 October 2012 - 10:27 AM Rate Topic: -----

#1 veena_vb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-October 12

need a different csv parser

Posted 06 October 2012 - 11:08 AM

i have csv file witch contains 4 tableinfo
for example
csv file format is like this:
file:
dog details[keyword dog details is used in csv to identify dog details start after this]
dog1; AAA ;AAAA; AAA; AAAA
dof2; AAA ;AAAA ;AAA;AAAAA
CAt details [keyword cat details is used in csv to identify cat details start after this]
cat1; AAA ;AAAA; AAA; AAAA
cat2; AAA ;AAAA ;AAA;AAAAA
bAt details [keyword bat details is used in csv to identify bat details start after this]
bat1; AAA ;AAAA; AAA; AAAA
bat2; AAA ;AAAA ;AAA;AAAAA

output look;
dog1 AAA
dog2 AAA
cat1 AAA
cat2 AAA
bat1 AAA
bat2 AAA

how i could parse this csv file in C# to get each animal details separately based on keyword given? any idea?

This post has been edited by tlhIn`toq: 06 October 2012 - 12:15 PM


Is This A Good Question/Topic? 0
  • +

Replies To: need a different csv parser

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5677
  • View blog
  • Posts: 12,208
  • Joined: 02-June 10

Re: need a different csv parser

Posted 06 October 2012 - 12:19 PM

looks like you just need to read the file and split at the ;

the output doesn't look hardly any different than the file.

have you coded anything? any attempt at all? what specific issue are you having with your code?
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,500
  • Joined: 29-May 08

Re: need a different csv parser

Posted 06 October 2012 - 02:15 PM

What about using TextFieldParser?
Was This Post Helpful? 1
  • +
  • -

#4 veena_vb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-October 12

Re: need a different csv parser

Posted 09 October 2012 - 08:46 AM

View PosttlhIn`toq, on 06 October 2012 - 12:19 PM, said:

looks like you just need to read the file and split at the ;

the output doesn't look hardly any different than the file.

have you coded anything? any attempt at all? what specific issue are you having with your code?



yes i have done bit coding part but seems to messier
i could add the algorithm/steps wat i have used in my code...
1: read the file
2; read lines till end of stream
3: then split the line using delimiter ;
4: After split the line, check first string is dog or cat ot bat
5: then if it is cat i have written method to fetch dog info

butstill i m not happy with this,...is there any possibilities to do this in linq...can anyone guide me
Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,500
  • Joined: 29-May 08

Re: need a different csv parser

Posted 09 October 2012 - 09:43 AM

What about my suggestion?
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,480
  • Joined: 05-May 12

Re: need a different csv parser

Posted 09 October 2012 - 10:01 AM

I think he didn't take time to read the documentation and see that TextFieldParser lets you configure the delimiters, including changing the default comma to a semicolon. Personally, I've been using the TextFieldParser ever since I was first clued into it a few years ago. It handles quotes and escapes which String.Split() does not.
Was This Post Helpful? 0
  • +
  • -

#7 veena_vb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-October 12

Re: need a different csv parser

Posted 09 October 2012 - 10:08 AM

View PostAdamSpeight2008, on 09 October 2012 - 09:43 AM, said:

What about my suggestion?

thanks for the reply...but this csv is not well structured...in the sense it can be like for example
dfgdfgd
werwer
werwer
dog details
col1 col2 col3
dog1 dog2 dog3
cat details
col1 col2 col3
cat1 cat2 cat3

so in this case ....how i could create parser? each time im reading line and searching for striung and then add details...is this correct?can anyone guide me
Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,500
  • Joined: 29-May 08

Re: need a different csv parser

Posted 09 October 2012 - 10:14 AM

If the data is delimited by the ; symbol then split on that.
Depending on the number of fields read in will indicate what type of data is.
Then examine them.

Also did you also look at Simple Scripting Language mentioned on the tutorial?
Was This Post Helpful? 0
  • +
  • -

#9 veena_vb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-October 12

Re: need a different csv parser

Posted 09 October 2012 - 10:27 AM

THANKS FOR THE REPLY...i ll checkit out...and i will post how i have done this...so u could have a look and comment on that
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1