"Hello a World b"와 같은 문자열이 있으면 문자 'a'와 'b'를 인쇄하고 'Hello'와 'World'를 무시할 수있는 방법이 있습니까?문자열에서 단일 문자 단어 만 추출 할 수있는 방법이 있습니까?
단일 문자 단어를 인쇄하고 여러 문자 문자열을 무시하고 싶습니다.
"Hello a World b"와 같은 문자열이 있으면 문자 'a'와 'b'를 인쇄하고 'Hello'와 'World'를 무시할 수있는 방법이 있습니까?문자열에서 단일 문자 단어 만 추출 할 수있는 방법이 있습니까?
단일 문자 단어를 인쇄하고 여러 문자 문자열을 무시하고 싶습니다.
희망 String 클래스
List <String> emoticons = new ArrayList();
for(String emoticon : emoticons) {
String input = "Hello :) World :P";
boolean output= input.contains(emoticon);
System.out.println("this emoticon "+emoticon+ is pressent);
}
에서 contains 방법을 사용합니다 ..
Matcher m = Pattern.compile("\\b[a-zA-Z]\\b").matcher(str);
while (m.find())
System.out.println(m.group());
결과는 같지만 코드는 적습니다. 공백으로 분할 된 모든 복수 문자 단어를 제거하는 것입니다.
for (String letter : str.replaceAll("\\w\\w+", "").trim().split(" +"))
System.out.println(letter);
이모티콘 매핑과이를 대체해야하는 문자가 필요합니다. 그런 다음지도를 반복하고 감정 (키)을 문자 (값) 및 설정으로 바꿉니다.
조금 물론이
Map<String, String> emoticons = new HashMap<String, String>();
//fill it with emoticons and what string should replace it
String s = "Hello :) World :P";
for(Map.Entry<String, String> entry: emoticons.entrySet()){
s = s.replace(entry.getKey(), entry.getValue());
}
것 같은데, 당신은 내가 도움이 :) 올바른 정규식
테스트를 통해 정확히 원하는 방식으로 작동하게했습니다. 정말 고맙습니다! 너는 생명의 은인이야! –