0

ここで正規表現に少し苦労しています。

「ジョン・スミスの生年月日は?」というような文があります。【生年月日】というキーワードを抽出したいのですが、文の後半に「の」という言葉が入っているのでどうしたらよいかわかりません。

ありがとう、グウェンダル

4

1 に答える 1

1

文字列の存在のみを確認したい場合はdate of birth、 メソッドを使用しString contains(CharSequence s)ます。

使用法

String str="what is the date of birth of John Smith";
str.contains("date of birth"); // Returns in Boolean whether the char sequence is present in s

指定した部分文字列の最初の出現を知りたい場合はint indexOf(String str)メソッドを使用します

使用法

String str="what is the date of birth of John Smith";
str.indexOf("date of birth"); // Returns the first pos of occurence of the substring

文字列の詳細については、このページを確認してください

于 2012-12-06T05:13:12.407 に答える