Array Join

From SwiftAPI

Jump to: navigation, search

Contents

C#

string[] a = {"9", "4", "0", "4", "0"};
string s = ".";
string r = String.Join(s, a);
// r == "9.4.0.4.0"

JavaScript

developer.mozilla.org

var a = [9, 4, 0, 4, 0];
var s = '.';
var r = a.join(s);
// r == '9.4.0.4.0'

Objective-C

developer.apple.com

- (NSString *)componentsJoinedByString:(NSString *)separator
NSArray *a = @[@"9", @"4", @"0", @"4", @"0"];
NSString *s = @".";
NSString *r = [a componentsJoinedByString:s];
// r == "9.4.0.4.0"

Perl

perldoc

join EXPR,LIST
@a = (9, 4, 0, 4, 0);
$s = '.';
$r = join($s, @a);
# $r == '9.4.0.4.0';

PHP

php.net

string implode ( string $glue , array $pieces )
string implode ( array $pieces )
$a = array(9, 4, 0, 4, 0);
$s = '.';
$r = implode($s, $a);
// $r == '9.4.0.4.0'

Python

docs.python.org

a = [9, 4, 0, 4, 0]
s = '.'
r = s.join(a)
# r == '9.4.0.4.0'

Ruby

a = [9, 4, 0, 4, 0]
s = '.'
r = a.join(s)
# r == '9.4.0.4.0'

Swift

let a = ["9", "4", "0", "4", "0"]
let s = "."
let r = join(s, a)
// r == "9.4.0.4.0"
Personal tools