String Contains

From SwiftAPI

Jump to: navigation, search

Tests whether a substring is contained within a string. For the languages that are not listed below, simply use String Index Of and test for the failure condition.

Contents

C#

msdn

System.String : public bool Contains(string value)
string s = "Hello World";
bool b;
 
b = s.Contains("World");
// b == true
 
b = s.Contains("Foo");
// b == false

Java

Java SE 6

java.lang.String : public boolean contains(CharSequence s)
String s = "Hello World";
boolean b;
 
b = s.contains("World");
// b == true
 
b = s.contains("Foo");
// b == false

JavaScript

var s = "Hello World";
var b;
 
b = s.indexOf("World") != -1;
// b == true
 
b = s.indexOf("Foo") != -1;
// b == false

Prototype

prototype

var s = "Hello World";
var b;
 
b = s.include("World");
// b == true
 
b = s.include("Foo");
// b == false

MooTools

mootools

var s = "Hello World";
var b;
 
b = s.contains("World");
// b == true
 
b = s.contains("Foo");
// b == false

PHP

$s = 'Hello World';
 
$b = strpos($s, 'World') !== false;
// $b == true
 
$b = strpos($s, 'Foo') !== false;
// $b == false

Python

s = 'Hello World'
 
b = 'World' in s
# b == True
 
b = 'Foo' in s
# b == False

Ruby

ruby-doc.org

str.include? other_str => true or false
str.include? fixnum => true or false
s = "Hello World"
 
b = s.include?("World")
# b == true
 
b = s.include?("Foo")
# b == false
Personal tools