2014-02-06 45 views
1

更換HTML代碼,我有字符串包含了像” & ’等我希望在Java中設置類似(" & ')各自的實體來代替它的HTML代碼。我試過下面的代碼。與字符實體


if (StringUtils.isNotBlank(string)) { 
    string = StringEscapeUtils.unescapeXml(string); 
    string = StringEscapeUtils.unescapeHtml(string); 
    string = string.replaceAll("<.*?>", ""); 
    string = string.trim(); 
} 

輸入字符串:

brief is a tie side, string style embellished with shimmering silver sequins. 
Dangling gunmetal chain tassels decorate the end of each hip tie. Model&amp;apos;s 
Measurements Height 5&amp;apos;10.5&amp;quot; Hips 36&amp;#148; Waist 23.5&amp;#148; 
Model wears size 2 

我得到以下輸出包含BadEncoding:

brief is a tie side, string style embellished with shimmering silver 
sequins. Dangling gunmetal chain tassels decorate the end of each hip tie. Model's 
Measurements Height 5'10.5" Hips 36<94> Waist 23.5<94> Bust 35<94> Model wears size 2 

所需的輸出:

brief is a tie side, string style embellished with shimmering silver sequins. 
Dangling gunmetal chain tassels decorate the end of each hip tie. Model's 
Measurements Height 5'10.5" Hips 36" Waist 23.5" Bust 35" Model wears size 2 

請建議。

+0

輸入以'breif'開頭,即'The Zonia bikini'的輸出。這是一個錯字嗎? – Behrang

+0

你打電話給'unescapeHtml3'還是'unescapeHtml4'? –

+0

我做了chaanges離子輸出線。@ Behrang – Tanay

回答