2016-09-08 5 views
1

このStringコンテンツを解析します。StringUtilsは文字列を含むコンマの分割に問題があります

requiredContent='Tigers that breed with lions give birth to hybrids known as "tigons" and "ligers."// In 19th-century Sweden, 380 kids were strangled by their mothers or nurses every year, according to the Swedish Statistical Bureau.' 

Iは

String[] factsArray = StringUtils.split(requiredContent, "//"); 

とそれを分割し、I 2の配列の長さを有していなければならない結果

[Tigers that breed with lions give birth to hybrids known as "tigons" and "ligers.", In 19th-century Sweden, 380 kids were strangled by their mothers or nurses every year, according to the Swedish Statistical Bureau.] 

得factsArrayを得たが、それは長さ4の配列を示しました。それは文字列に含まれている "、"を持つ文字列を解析していました。これは起こるべきではない、これを修正する方法???

答えて

0

それ

コンマ配列コンマ区切りと文字列の間の表示でちょうど競合がfactsArray.length結果を検証だ、それは2だと4

0

私は二重引用符を使用し、言葉のためにそれらをエスケープする文字列を変更していませんこの問題を再現しようとしました。 ApacheCommonsのlang3バージョン3.4の使用:

String requiredContent = "Tigers that breed with lions give birth to hybrids known as \"tigons\" and \"ligers.\"// In 19th-century Sweden, 380 kids were strangled by their mothers or nurses every year, according to the Swedish Statistical Bureau."; 
String[] factsArray = StringUtils.split(requiredContent, "//"); 

をそして、私は2の配列の長さを得るか、私は配列の内容の表示がめちゃめちゃにすることができると思い。私は、配列の長さを持っ

0
String requiredContent = "Tigers that breed with lions give birth to hybrids known as \"tigons\" and \"ligers.\"// In 19th-century Sweden, 380 kids were strangled by their mothers or nurses every year, according to the Swedish Statistical Bureau."; 
     List factsArray = StringUtils.split(requiredContent, "//", true); 
     for (int i = 0; i < factsArray.size(); i++) { 
      System.out.println(factsArray.get(i)); 
     } 
output: 

Tigers that breed with lions give birth to hybrids known as "tigons" and "ligers." 
In 19th-century Sweden, 380 kids were strangled by their mothers or nurses every year, according to the Swedish Statistical Bureau. 
関連する問題