Substring

From SwiftAPI

Jump to: navigation, search

Contents

C++

msdn

string substr ( size_t pos = 0, size_t n = npos ) const;
#include <string>
using namespace std;
 
string s = "Hello World";
int start = 6;
s = s.substr(start);
// s == "World"
#include <string>
using namespace std;
 
string s = "Hello World";
int start = 2;
int end = 7;
s = s.substr(start, end - start);
// s == "llo W"

C#

msdn

System.String : public string Substring(int startIndex)
System.String : public string Substring(int startIndex, int length)
string s = "Hello World";
int start = 6;
s = s.Substring(start);
// s == "World"
string s = "Hello World";
int start = 2;
int end = 7;
s = s.Substring(start, end - start);
// s == "llo W"

Java

J2SE 1.4.2

public String substring(int beginIndex)
public String substring(int beginIndex, int endIndex)

JavaScript

substring

Mozilla msdn

var s = "Hello World";
var start = 6;
s = s.substring(start);
// s == "World"
var s = "Hello World";
var start = 2;
var end = 7;
s = s.substring(start, end);
// s == "llo W"

substr

mozilla msdn

var s = "Hello World";
var start = 6;
s = s.substr(start);
// s == "World"
var s = "Hello World";
var start = 2;
var end = 7;
s = s.substr(start, end - start);
// s == "llo W"

slice

[1]

var s = "Hello World";
var start = 6;
s = s.slice(start);
// s == "World"
var s = "Hello World";
var start = 2;
var end = 7;
s = s.slice(start, end);
// s == "llo W"

Objective-C

developer.apple.com

- (NSString *)substringWithRange:(NSRange)aRange
- (NSString *)substringFromIndex:(NSUInteger)anIndex
- (NSString *)substringToIndex:(NSUInteger)anIndex
NSString *s = @"Hello World";
int start = 6;
s = [s substringFromIndex:start];
// s == 'World'
NSString *s = @"Hello World";
int start = 2;
int length = 5;
s = [s substringWithRange:NSMakeRange(2, 5)];
// s == 'World'

Perl

perldoc

substr EXPR,OFFSET,LENGTH,REPLACEMENT
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET
$s = 'Hello World';
$start = 6;
$s = substr $s, $start;
# s == 'World'
$s = 'Hello World';
$start = 2;
$end = 7;
$s = substr $s, $start, $end - $start;
# s == 'llo W'

PHP

php.net

string substr( string $string , int $start [, int $length ] )
$s = 'Hello World';
$start = 6;
$s = substr($s, $start);
// s == 'World'
$s = 'Hello World';
$start = 2;
$end = 7;
$s = substr($s, $start, $end - $start);
// s == 'llo W'

Python

s = 'Hello World'
start = 6
s = s[start:]
# s == 'World'
s = 'Hello World'
start = 2
end = 7
s = s[start:end]
# s == 'llo W'

Ruby

Ruby-Doc.org

s = s[start..-1]
s = s[start..end]

Visual Basic .NET

msdn

Public Function Substring ( startIndex As Integer ) As String
Public Function Substring ( startIndex As Integer, length As Integer ) As String
Personal tools