大きな文字列をJavaで分割しようとしています。他の文字列でもうまくいきましたが、この大きなサイズの文字列を分割しようとすると文字列の一部しか分割されません。他の部分はまだ同じで、分割されていません。" "のxmlクエリから大きなサイズの文字列をJavaで分割する
私がこれまで行ってきたこと:私はsplit()
機能を使用していますが、それは機能しません。第二に、私は正規表現("[\\\\r\\\\n]+")
に基づくスプリットを使用して、配列リストに入れて、そこから交換してみてください、それはまた、動作しません
私の最初のコード:
String string;
string = AudioSpectrumProjectionType().trim();
String[] hasil = string.split("
");
for(int i = 0 ; i<hasil.length;i++){
System.out.print(hasil[i].trim().replace(" ",","));
if (i%20 == 0)
System.out.print("\n");
if(i != hasil.length-1)
System.out.print(",");
}
私の第二のコード:
ArrayList<String> arrayList = new ArrayList<String>();
String string;
string = AudioSpectrumProjectionType().trim();
String[] hasil = string.split("[\\r\\n]+");
for(int i = 0 ; i<hasil.length;i++){
arrayList.add(hasil[i].trim());
}
for(int i = 0 ; i<arrayList.size();i++){
String print = arrayList.get(i);
System.out.println(print.replaceAll("
",""));
}
AudioSpectrumProjectionType()関数ここでは、XMLからわずかクエリですコードは次のとおりです。
private static String AudioSpectrumProjectionType() throws BaseXException{
String query =
"declare default element namespace \"urn:mpeg:mpeg7:schema:2001\";" +
"declare namespace mpeg7 = \"urn:mpeg:mpeg7:schema:2001\";" +
"declare namespace xsi = \"http://www.w3.org/2001/XMLSchema-instance\";" +
"for $x in doc(\"C:/Users/ponighzwa/IdeaProjects/ExtractDescriptor/cover/lagu/voice isolation 2/xml/original/perempuan/The One That Got Away.xml\")/Mpeg7/Description/MultimediaContent/Audio/AudioDescriptor\n return if($x/@xsi:type=\"AudioSpectrumProjectionType\")then data($x/SeriesOfVector/Raw) else \"\"";
System.out.println(new XQuery(query).execute(context));
String hasil = new XQuery(query).execute(context);
return hasil;
}
私が好き期待する結果:私が得る
0.6324845 0.48125452 0.2834291 0.51651007 0.47841766 0.36249334 0.3128651
結果:
769.31354 -0.991627 -0.008771153 -0.0958663 0.047845073 -0.02021278 -0.03738797 0..0136948135
2615.384 -0.99431473 0.024853256 -0.07093173 0.0330488 -0.03610177 -0.03400125 0.014497152 0.0082630105
2615.384 -0.99431473 0.024853256 -0.07093173 0.0330488 -0.03610177 -0.03400125 0.014497152 0.0082630105
2615.384 -0.99431473 0.024853256 -0.07093173 0.0330488 -0.03610177 -0.03400125 0.014497152 0.0082630105
2615.384 -0.99431473 0.024853256 -0.07093173 0.0330488 -0.03610177 -0.03400125 0.014497152 0.0082630105
2615.384 -0.99431473 0.024853256 -0.07093173 0.0330488 -0.03610177 -0.03400125 0.014497152 0.0082630105
を私は " " せずにそれを必要とし、誰もがこれまでと同じ問題が発生しましたか?
ルックスは分割されていません。代わりに、あなたの文字列に異なるセパレータがあります。おそらく最初の半分だけが行のセパレータとして ' 'を持っています。だから " "を "\ r \ n" + "に分割するよりも先に" \ r \ n "に置き換えなければなりません。 –