私はファイルを書く作業をしています。ループのような文字列配列を持っています それを書いているすべての値に二重引用符を付ける必要がありますファイル。二重引用符( "")を使用して文字列配列を作成する
region.append("\"").append(a[z]).append("\"").append(',');
私はファイルを書く作業をしています。ループのような文字列配列を持っています それを書いているすべての値に二重引用符を付ける必要がありますファイル。二重引用符( "")を使用して文字列配列を作成する
region.append("\"").append(a[z]).append("\"").append(',');
に文字列Array.Thanks内のすべての値のための二重引用符を追加する方法を私を助けることができますあなたはおそらく何をしたいのJava 8は、
各文字列のString region = Arrays.stream(a)
.map(s -> String.format("\"%s\"", s)) // add double quotes around each string
.collect(Collectors.joining(","); // comma-separate values
例:
int l = myStrings.length;
for(int i = 0; i < l; i++){
// Adds " to the begning of the string and ", to the end of the string.
myStrings[i] = "\"" + mystrings[i] + "\",";
// if you want to use String.format:
//myStrings[i] = String.format("\"%s\",", myStrings[i]);
// if it is the last string, remove the unwanted comma
if(i == l-1){
// gets the substring of the last string in the array, excluding only
// the last character, because it is an unwanted comma
myStrings[i] = myStrings[i].substring(0,l);
}
// Write in your file here
// region.append(myStrings[i]);
}
はあなたがが、まだ何かをしようとしたことがありますか? –
Yead、配列値に二重引用符を付けることができました。これを試しました "+" [x] + "\" " あなたのご意見をお寄せいただきありがとうございます。 – veda