함수 contains()

  다른 뜻에 대해서는 import 문서를 참조하십시오.

1 개요[ | ]

contains
.include

2 ALGOL 68[ | ]

html
Copy
 string in string("e", loc int, "Hello mate");      ¢ returns true ¢
 string in string("z", loc int, "word");            ¢ returns false ¢

3 C#[ | ]

C#
Copy
"Hello mate".Contains("e");      // returns true
"word".Contains("z");            // returns false

4 Excel[ | ]

PHP
Copy
=ISNUMBER(SEARCH("hello", "hello world"))
// TRUE
=ISNUMBER(SEARCH("olleh", "hello world"))
// FALSE
PHP
Copy
=NOT(ISERR(FIND("hello","hello world")))
// TRUE
=NOT(ISERR(FIND("olleh","hello world")))
// FALSE
PHP
Copy
=ISERR(FIND("hello","hello world"))
// FALSE
=ISERR(FIND("olleh","hello world"))
// TRUE

5 Go[ | ]

Go
Copy
package main

import "fmt"
import "strings"

func main() {
	// true
	fmt.Println(strings.Contains("Hello mate", "e"))
	fmt.Println(strings.Contains("Hello mate", "llo"))

	// false
	fmt.Println(strings.Contains("word", "z"))
	fmt.Println(strings.Contains("word", "war"))
}
Loading

6 Java[ | ]

Java 1.5+
Java
Copy
"Hello mate".contains("e");      // returns true
"word".contains("z");            // returns false

7 JavaScript[ | ]

JavaScript
Copy
console.log( "Hello mate".indexOf("e") > -1 );      // true
console.log( "word".indexOf("z") > -1 ); // false

8 PHP[ | ]

PHP
Copy
function contains($str, $text) { return (strpos($text, $str) !== false); }

var_dump( contains("ll", "Hello mate"));  # bool(true)
var_dump( contains("ate", "Hello mate")); # bool(true)

var_dump( contains("z", "Hello mate"));     # bool(false)
var_dump( contains("hello", "Hello mate")); # bool(false)

9 Python[ | ]

Python
Copy
print( "ll" in "Hello mate" )  # True
print( "ate" in "Hello mate" ) # True

print( "z" in "Hello mate" )     # False
print( "hello" in "Hello mate" ) # False

10 Perl[ | ]

Perl
Copy
( "Hello mate" =~ /e/ ); # returns true
( "Hello mate" =~ /Z/ ); # returns false

11 R[ | ]

R
Copy
grepl("ll", "Hello mate")  ## [1] TRUE
grepl("ate", "Hello mate") ## [1] TRUE

grepl("z", "Hello mate")     ## [1] FALSE
grepl("hello", "Hello mate") ## [1] FALSE

12 Ruby[ | ]

Ruby
Copy
puts "Hello mate".include?("e")
# true
puts "word".include?("z")
# false
puts "Hello mate".include?("ll") 
# true

13 같이 보기[ | ]

14 참고[ | ]