Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/string/investigation_char/investigation_char.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/string/investigation_char/investigation_char.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/string/investigation_char/investigation_char.html on line 2
文字列に指定した文字が含まれるか調査 | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/string/investigation_char/investigation_char.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/string/investigation_char/investigation_char.html on line 17
文字列に指定した文字が含まれるか調査
文字列に、ある値が含まれるかを調査したい場合、StringクラスのindexOfメソッドを使用します。
このメソッドは、引数に調べたい値を渡します。
メソッドの戻り値は、指定された文字が最初に出現する位置のインデックスになります。また指定した文字が存在しない場合は -1 を返しますのでそれを利用します。

以下、例です。

public class Test{
    public static void main(String[] args) {
        String str = new String("abcd.");
        
        if(str.indexOf(".") == -1){
            System.out.println("含まれない");
        }else{
            System.out.println("含まれる位置は"+ str.indexOf("."));
        }
    }
}
実行結果は以下のようになります。

含まれる位置は4

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/string/investigation_char/investigation_char.html on line 75

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/string/investigation_char/investigation_char.html on line 75

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/string/investigation_char/investigation_char.html on line 84

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/string/investigation_char/investigation_char.html on line 84