Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
FileReader を介して読み取る CSV ファイルがあります。readLine は、CSV ファイルの最初の行を文字列として提供します。
文字列 str = 1,1,1,"12345",名前,"猫,犬";
コンマ (,) は区切り文字であり、文字列を分割すると、出力が得られます
1 1 12345 名前「猫犬」
しかし、この出力の代わりに、何らかの値が ""(二重引用符) に含まれている場合、その場合は完全な値を取る必要があります (分割せずに)
1 1 12345 名前 猫、犬
これを試してください:
String line = "1,1,1,\"12345\",Name,\"Cat,Dog\""; if (line.contains("\"")) { line = line.replaceAll("(\"\\,|\\,\")|\\,|\"$", " "); System.out.println(line); }else { // code to split the line }
出力:1 1 1 12345 Name Cat Dog
1 1 1 12345 Name Cat Dog