+ Start a Discussion
unidhaunidha 

CSV File data contain coma and enclosed by double quote

Hi,

 

I know the Data loader have the features to accept data contain coma with condition it must enclosed with double quote.I want to know how to code it using apex class.

 

For example CSV File  contain data  "ACME", "Acme,Owner ,Friend", "000"

 

I want the data to be read as below.It should retun 3 columns.

ACME

Acme,Owner,Friend

000

 

Currently the code that I have is working like this.It return 5 columns.

"ACME"

"Acme

Owner

Friend"

"000"

 

I tried this http://wiki.developerforce.com/page/Code_Samples#Parse_a_CSV_with_APEX but didn't get the result that I want.

Any idea?

 

Thanks,

unidha

Best Answer chosen by Admin (Salesforce Developers) 
unidhaunidha

Thanks 

 

for (Integer i=1;i<filelines.size();i++)
  {
      String[] inputvalues = new String[]{};
      inputvalues = filelines[i].split('",');
              
       MyObject a = new MyObject  ();
       a.Name = inputvalues[0].replace('"','');
       a.Detail= inputvalues[1].replace('"','');       
       a.Number = inputvalues[2].replace('"','');
   
   }

 Thanks,

unidha

All Answers

Jeff MayJeff May

Your apex class will need to make a pre-pass through each line and find combinations of ", or ," and replace them with a 'noticaable' string.  You can then parse on the 'noticeable' string and get your columns and data.

unidhaunidha

Thanks 

 

for (Integer i=1;i<filelines.size();i++)
  {
      String[] inputvalues = new String[]{};
      inputvalues = filelines[i].split('",');
              
       MyObject a = new MyObject  ();
       a.Name = inputvalues[0].replace('"','');
       a.Detail= inputvalues[1].replace('"','');       
       a.Number = inputvalues[2].replace('"','');
   
   }

 Thanks,

unidha

This was selected as the best answer