-13

私はString好きです、

 String test = "voiceemailchat";
 String find = "chat";

新しい単語が既存の単語に既に存在するかどうかを確認する必要があります。

状態は次のようになります。

if(test has find)
      //go something
else
      //go somethig

Javaで可能ですか?

4

5 に答える 5

9

はい、可能です:

String test = "voiceemailchat";
String find = "chat";

if(test.contains(find)) {
    //string found
}
于 2013-09-13T09:37:08.710 に答える
3

どうですか -

if(test.indexof(find)>-1){
  ... // found
}
于 2013-09-13T09:37:48.430 に答える
3

次のコードを実行します。大きなデータ ファイルまたは文字列がある場合は、正規表現を使用します。最高です。

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexMatches
{
    public static void main( String args[] ){

      // String to be scanned to find the pattern.
      String line = "voiceemailchat";
      String pattern = "chat";

      // Create a Pattern object
      Pattern r = Pattern.compile(pattern);

      // Now create matcher object.
      Matcher m = r.matcher(line);
      if (m.find( )) {
         System.out.println("Found the value");
      } else {
         System.out.println("NO MATCH");
      }
   }
}
于 2013-09-13T10:07:28.673 に答える