2014-11-26 2 views

답변

1

희망 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); 
+0

테스트를 통해 정확히 원하는 방식으로 작동하게했습니다. 정말 고맙습니다! 너는 생명의 은인이야! –

0

이모티콘 매핑과이를 대체해야하는 문자가 필요합니다. 그런 다음지도를 반복하고 감정 (키)을 문자 (값) 및 설정으로 바꿉니다.

조금 물론이

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()); 
} 
0

것 같은데, 당신은 내가 도움이 :) 올바른 정규식

관련 문제