Ends With (string)

From SwiftAPI

Jump to: navigation, search

Contents

C#

string s = "hello world";
 
string suffix = "world";
bool b = s.EndsWith(suffix);
// b == true
 
suffix = "hello";
b = s.EndsWith(suffix);
// b == false

Java

J2SE 1.4.2

java.lang.String : public boolean endsWith(String suffix)
String s = "hello world";
 
String suffix = "world";
boolean b = s.endsWith(suffix);
// b == true
 
suffix = "hello";
b = s.endsWith(suffix);
// b == false

JavaScript

Firefox 17+, Chrome 41+, Prototype

MDN prototype

var s = "hello world";
 
var suffix = "world";
var b = s.endsWith(suffix);
// b == true
 
suffix = "hello";
b = s.endsWith(suffix);
// b == false

Objective-C

developer.apple.com

- (BOOL)hasSuffix:(NSString *)aString
NSString *s = @"hello world";
 
NSString *suffix = @"world";
BOOL b = [s hasSuffix:suffix];
// b == YES
 
suffix = @"hello";
b = [s hasSuffix:suffix];
// b == NO

Python

docs.python.org

s = "hello world"
 
suffix = "world"
b = s.endswith(suffix)
# b == True
 
suffix = "hello"
b = s.endswith(suffix)
# b == False

Swift

developer.apple.com

let s = "hello world"
 
let suffix = "world"
let b = s.hasSuffix(suffix)
// b == true
 
let suffix2 = "hello"
let b2 = s.hasSuffix(suffix2)
// b2 == false
Personal tools