2016-09-08 4 views
1

이 String Content를 구문 분석하려고합니다.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.' 

제가

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

나는 따옴표를 사용하여 단어를 탈출 문자열을 수정하지 tigons 및 ligers 및 문제를 재현하려고합니다.

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)의 배열의 길이를받을 수 있나요 : 아파치 커먼즈에게 lang3 버전 3.4을 사용. 난 배열 길이를 가지고

0

2

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.