함수 substr_count()



개요

함수 substr_count()

Java

import java.util.regex.Pattern;
public class MyClass {
    public static void main(String args[]) {
        String s = "This is a test";
        String sub = "is";
        int count = s.split(sub,-1).length-1;
        System.out.println( count ); // 2
    }
}

PHP

echo substr_count('This is a test', 'is'); # 2
echo substr_count("Hello world. The world is nice","world"); # 2

Python

s = "Hello world. The world is nice"
print( s.count("world") ) # 2

같이 보기