"함수 substr count()"의 두 판 사이의 차이

22번째 줄: 22번째 줄:
[[분류: PHP]]
[[분류: PHP]]
{{참고|PHP substr_count()}}
{{참고|PHP substr_count()}}
<syntaxhighlight lang='php'>
<syntaxhighlight lang='php' run>
echo substr_count('This is a test', 'is');
echo substr_count('This is a test', 'is'); # 2
# 2
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='php'>
<syntaxhighlight lang='php' run>
echo substr_count("Hello world. The world is nice","world");
echo substr_count("Hello world. The world is nice","world"); # 2
# 2
</syntaxhighlight>
</syntaxhighlight>



2021년 4월 14일 (수) 18:54 판


1 개요

함수 substr_count()

2 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
    }
}

3 PHP

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

4 Python

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

5 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}