简体   繁体   中英

Java split with the characters that are not the indicated delimiters for .csv file

I have this string:

String newstring = "2018 Panini PRIZM DEVONTE GRAHAM SILVER Prizm #288 ROOKIE PSA 10 GEM MT HORNETS /split/ 2017-18 Panini Prizm Prizms Silver #16 Jayson Tatum Rookie PSA 10 Gem Mint RC"

I am currently using the split function as newstring.split("/split/") to obtain the two separate strings, then output as on a .csv file, and it works fine.

However, now I am given this string:

String anotherstring = " 2017-18 Panini Prizm Prizms Silver #16 Jayson Tatum Rookie PSA 10 Gem Mint RC /split/ Ja Morant prizm rc , silver, base, college, PSA 10? Great cards no scratches"

If I use the code above on anotherstring , I will have 6 strings, but not 2 as I expect. From what I tested, the split function also split by the comma sign which was not what I indicated as the delimiter. I think that my problem is that I am trying to export it as a .csv file. But how can I still export the file as .csv but not getting the values sprinkled?

EDIT:

Here are the Strings that I obtained in the .csv file when I run the code:

2017-18 Panini Prizm Prizms Silver #16 Jayson Tatum Rookie PSA 10 Gem Mint RC
Ja Morant prizm rc 
silver
base
college
?? PSA 10? Great cards no scratches

You can include commas inside csv's you just need to ensure that the entire piece of data is quoted. Here is an example:

1,2,a,b,3 will be 5 string however 1,2,"a,b",3 is only 4 strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM