String Length

From SwiftAPI

Jump to: navigation, search

Contents

C

msdn

#include <string.h>
 
char* s = "Hello World";
int n = strlen(s);
// n == 11

C++

msdn

#include <string>
using namespace std;
 
string s = "Hello World";
int n = s.length();
// n == 11

C#

msdn

System.String : public int Length { get; }
string s = "Hello World";
int n = s.Length;
// n == 11

Java

J2SE 1.4.2

java.lang.String : public int length()
String s = "Hello World";
int n = s.length();
// n == 11

JavaScript

Mozilla msdn

var s = "Hello World";
var n = s.length;
// n == 11

Objective-C

developer.apple.com

@property(readonly) NSUInteger length
NSString *s = @"Hello World";
int n = s.length;
// n == 11

Perl

perldoc.perl.org

length EXPR
$s = "Hello World";
$n = length($s);
# $n == 11

PHP

php.net

int strlen ( string $string )
$s = "Hello World";
$n = strlen($s);
// $n == 11

Python

docs.python.org

len(s)
s = "Hello World"
n = len(s)
# n == 11

Ruby

Ruby-Doc.org

str.length => integer
s = "Hello World"
n = s.length
# n == 11

Swift

Swift 1.2+

let s = "Hello World"
let n = count(s)
// n == 11

Swift 1.0-1.1:

let s = "Hello World"
let n = countElements(s)
// n == 11

Visual Basic .NET

msdn

System.String : Public ReadOnly Property Length As Integer
Dim s As String = "Hello World"
Dim n As Integer = s.Length
' n == 11
Personal tools