Can someone elaborate and explain this kind of code. I would like to know more information on it to build a database

こ雲淡風輕ζ 提交于 2019-12-11 05:49:29

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/25187900/can-someone-elaborate-and-explain-this-kind-of-code-i-would-like-to-know-more-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!