어디서나 배치 할 수있는 특정 String
문자열을 분할해야하며 (이 문자열이 동시에 여러 번 나타날 수 있음) 추출물을 추가하여 전체 문자열을 재구성해야합니다. StringBuffer
.문자열에서 동일한 문자열 double을 추출하십시오.
String targeted = "test" ;
String plainString ="azertytestqwerty";
//desired outcome
StringBuffer sb = new StringBuffer();
sb.append("azerty");
sb.append("test");
sb.append("qwerty");
--------------------------
String targeted = "test" ;
String plainString ="a.test";
//desired outcome
StringBuffer sb = new StringBuffer();
sb.append("a.");
sb.append("test");
--------------------------
String targeted = "test" ;
String plainString ="test mlm";
//desired outcome
StringBuffer sb = new StringBuffer();
sb.append("test");
sb.append("mlm");
--------------------------
String targeted = "test" ;
String plainString ="aaatestzzztest";
//desired outcome
StringBuffer sb = new StringBuffer();
sb.append("aaa");
sb.append("test");
sb.append("zzz");
sb.append("test");
이 작업을 수행하는 모든 간단한 방법 : 추구하는 특정 문자열의 경우는 예를 들어
문자를 구분해야 하는가?
Pattern pattern = Pattern.compile(".*"+targeted +".*");
Matcher matcher = pattern.matcher(text);
if (matcher.find())
{
System.out.println(matcher.group(1));
}
그러나 나는 문자열을 추출하는 방법을 알고 난이 그것의 할 이유 같은 순서
이유에 추가하지 않습니다
나는 내가 좋아하는 정규식을 사용할 필요가 있다고 생각 plainString
이 POI를 사용하여 Excel 셀에 추가되기 때문에 대상 문자열에 글꼴 색을 추가해야합니다.
예 :
XSSFRichTextString richString = new XSSFRichTextString();
richString.append("azerty");
richString.append("test", highlightFont);
richString.append("qwerty");
cell.setCellValue(richString);
이
그냥 단어를 분할 할 ... 당신에게
이처럼 StringBuffer에 추가하는 목표는 무엇입니까? "문자열 전체를 재구성하는 경우"그냥 뭐하는 거지? 'StringBuffer sb = new StringBuffer (plainString); ' – dustinroepsch
@Dustin Ryan-Roepsch. 게시물이 더 정밀하게 편집되었습니다. 대단히 감사합니다 :) – ulquiorra
Gotcha! 그것은 훨씬 더 의미가 있습니다 :) – dustinroepsch