Reputation: 3568
Here is the code example in which I got from https://www.ars.usda.gov/Services/docs.htm?docid=8964 . I have not found an example in which explains this type of code or how I would import it into SQLite database . After a little understanding of the code I should be able to work with it. Language java.
~01001~^~0100~^~Butter, salted~^~BUTTER,WITH SALT~^~~^~~^~Y~^~~^0^~~^6.38^4.27^8.79^3.87
~01002~^~0100~^~Butter, whipped, with salt~^~BUTTER,WHIPPED,WITH SALT~^~~^~~^~Y~^~~^0^~~^6.38^4.27^8.79^3.87
~01003~^~0100~^~Butter oil, anhydrous~^~BUTTER OIL,ANHYDROUS~^~~^~~^~Y~^~~^0^~~^6.38^4.27^8.79^3.87
Upvotes: 1
Views: 70
Reputation: 934
It seems what you need to do is write your own parser for this data. I don't know of any android libraries built specifically for this type of parsing but it wouldn't be that hard to do.
Something like, where document is a list of each line of the file.
for(string line : document)
string[] values = line.split("^");
for(string value : values)
//Add to database
That will give you all the values for each line. It looks as though strings are surrounded by ~~. So to check for string
if(value.CharAt(0) == '~' && value.CharAt(value.length -1))
and a null value would be
if("~~".equals(value))
Looking at the document you linked though it appears they don't offer column headings for you so you will have to set these manually for each file you have to parse.
Upvotes: 2
Reputation: 522
Its a delimited string/file. Flat file systems use this feature to seperate data, ie into columns. They usually go by /n (new line) for each row. Not a Java guy so Im hoping someone else can explain it with code. You would break up the fields and add them to your database. Hope it helps at least a bit.
Upvotes: 0