String Split

From SwiftAPI

Jump to: navigation, search

Contents

Java

J2SE 1.4.2

java.lang.String : public String[] split(String regex[, int limit])
String s = "a,b,c";
String[] a = s.split(',');
// a == ["a", "b", "c"]

JavaScript

Mozilla msdn

stringObj.split([separator[, limit]])
var s = "a,b,c";
var a = s.split(",");
// a == ["a", "b", "c"]

Objective-C

developer.apple.com

- (NSArray *)componentsSeparatedByString:(NSString *)separator
NSString *s = @"a,b,c";
NSArray *a = [s componentsSeparatedByString:@","];
// a == ["a", "b", "c"]

Perl

perldoc

split /PATTERN/,EXPR,LIMIT
split /PATTERN/,EXPR
split /PATTERN/
split
$s = 'a,b,c';
@a = split(',', $s);
# @a == ('a', 'b', 'c')

PHP

php.net

array explode ( string $delimiter , string $string [, int $limit ] )
$s = 'a,b,c';
$a = explode(',', $s);
// $a == array('a', 'b', 'c')

Python

docs.python.org

str.split([sep[, maxsplit]])
s = 'a,b,c'
a = s.split(',')
# a == ['a', 'b', 'c']

Ruby

s = "a,b,c"
a = s.split(",")
# a == ["a", "b", "c"]

Swift

import Foundation

let s = "a,b,c"
let a = s.componentsSeparatedByString(",")
// a == ["a", "b", "c"]
Personal tools