Content deleted Content added
Mindmatrix (talk | contribs) update to Raku (programming language) |
|||
Line 125:
|-
| <code>substr(''string'', ''i'', 1)</code> <br /> <code>''string.substr(''i'', 1)</code>
|[[
|0
|-
Line 195:
# Example in Perl 5
substr("Hello, World", 1, 1); # 'e'
</syntaxhighlight>▼
<syntaxhighlight lang="perl6">▼
# Example in Perl 6▼
"Hello, World".substr(1, 1); # 'e'▼
</syntaxhighlight>
Line 206 ⟶ 201:
"Hello, World"[2] # 'l'
"Hello, World"[-3] # 'r'
▲</syntaxhighlight>
▲<syntaxhighlight lang="perl6">
▲"Hello, World".substr(1, 1); # 'e'
</syntaxhighlight>
Line 261:
|-
| <code>''string<sub>1</sub>'' cmp ''string<sub>2</sub>''</code>
|[[Perl
|-
| <code>''string<sub>1</sub>'' compare: ''string<sub>2</sub>''</code>
Line 330:
# Example in Perl 5
"hello" cmp "world"; # returns -1
</syntaxhighlight>▼
<syntaxhighlight lang="python">▼
# Example in Python▼
cmp("hello", "world") # returns -1▼
</syntaxhighlight>
<syntaxhighlight lang="perl6">
# Examples in
"hello" cmp "world"; # returns Less
"world" cmp "hello"; # returns More
"hello" cmp "hello"; # returns Same
▲</syntaxhighlight>
▲<syntaxhighlight lang="python">
▲# Example in Python
▲cmp("hello", "world") # returns -1
</syntaxhighlight>
Line 404:
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>''eq'', ''ne'', ''lt'', ''gt'', ''le''</code> and <code>''ge''</code>
|[[Perl
|-
| <code>''string<sub>1</sub>'' OP ''string<sub>2</sub>''</code>, where <code>OP</code> can be any of <code>==, !=, <, >, <=</code> and <code>>=</code>
Line 437:
<syntaxhighlight lang="perl6">
# Example in
"art" gt "painting"; # returns False
"art" lt "painting"; # returns True
Line 483:
|-
| <code>''string<sub>1</sub>'' ~ ''string<sub>2</sub>''</code>
|[[D (programming language)|D]], [[
|-
| <code>(string-append ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>
Line 563:
<syntaxhighlight lang="perl6">
# Example in
"abc" ~ "def"; # returns "abcdef"
"Perl " ~ 6; # returns "
</syntaxhighlight>
<!-- endsection -->
Line 599:
|-
| <code>''string''.contains(''substring'')</code>
| [[Cobra (programming language)|Cobra]], [[Java (programming language)|Java]] (1.5+), [[
|-
| <code>''string''.indexOf(''substring'') >= 0</code>
Line 672:
</syntaxhighlight>
<syntaxhighlight lang="perl6">▼
# Example in Perl 6▼
"Good morning!".contains('z') # returns False▼
"¡Buenos días!".contains('í'); # returns True▼
</syntaxhighlight>▼
<syntaxhighlight lang="python">
# Example in Python
"e" in "Hello mate" # returns true
"z" in "word" # returns false
▲</syntaxhighlight>
▲<syntaxhighlight lang="perl6">
▲"Good morning!".contains('z') # returns False
▲"¡Buenos días!".contains('í'); # returns True
</syntaxhighlight>
Line 723:
|-
| <code>''string<sub>1</sub>'' eq ''string<sub>2</sub>''</code>
|[[Perl
|-
| <code>''string<sub>1</sub>''.equals(''string<sub>2</sub>'')</code>
Line 758:
<syntaxhighlight lang="perl6">
# Examples in
'hello' eq 'world' # returns False
'hello' eq 'hello' # returns True
Line 813:
|-
| <code>index(''string'',''substring''«,''startpos''»)</code> <br /> <code>''string''.index(''substring'',«,''startpos''»)</code>
|[[Raku (programming language)|Raku]]
|returns Nil
|-
Line 958:
<syntaxhighlight lang="perl6">
# Examples in
"Hello, there!".index('e') # returns 1
"Hello, there!".index('z') # returns Nil
Line 1,127:
|-
| <code>[[sprintf]](''formatstring'', ''items'')</code>
|[[Perl
|C
|-
| <code>item.fmt(''formatstring'')</code>
|[[Raku (programming language)|Raku]]
|C
|-
Line 1,251:
<syntaxhighlight lang="perl6">
# Examples in
sprintf "My %s costs \$%.2f", "pen", 19.99; # returns "My pen costs $19.99"
1.fmt("%04d"); # returns "0001"
Line 1,294:
|-
| <code>''string<sub>1</sub>'' ne ''string<sub>2</sub>''</code>
|[[Perl
|-
| <code>(string<> ''string<sub>1</sub>'' ''string<sub>2</sub>'')</code>
Line 1,354:
<syntaxhighlight lang="perl6">
# Example in
'hello' ne 'world' # returns True
</syntaxhighlight>
Line 1,399:
|-
| <code>join(''separator'', ''list_of_strings'')</code>
|[[Perl
|-
| <code>implode(''separator'', ''array_of_strings'')</code>
Line 1,408:
|-
| <code>''array_of_strings''.join(''separator'')</code>
|[[Ruby (programming language)|Ruby]], [[JavaScript]], [[
|-
| <code>(string-join ''array_of_strings'' ''separator'')</code>
Line 1,483:
<syntaxhighlight lang="perl6">
# Example in
<a b c>.join('-'); # 'a-b-c'
</syntaxhighlight>
Line 1,524:
|-
| <code>substr(''string'', 0, ''n'')</code>
|[[AWK]] (changes string), [[Perl
|-
| <code>LEFT$(''string'',''n'')</code>
Line 1,536:
|-
| <code>''string''.substr(0,''n'')</code>
|[[C++]] (STL), [[
|-
| <code>[''string'' substringToIndex:''n'']</code>
Line 1,618:
<syntaxhighlight lang="perl6">
# Example in
"Hello, there!".substr(0, 6); # returns "Hello,"
</syntaxhighlight>
Line 1,698:
| <code>chars(''string'')</code> <br /> <code>''string''.chars</code>
|Number of graphemes (NFG)
|[[Raku (programming language)|Raku]]
|-
| <code>codes(''string'')</code> <br /> <code>''string''.codes</code>
|Number of Unicode code points
|[[Raku (programming language)|Raku]]
|-
| <code>''string''.size OR ''string''.length</code>
Line 1,819:
<syntaxhighlight lang="perl6">
# Examples in
"🏳️🌈".chars; chars "🏳️🌈"; # both return 1
"🏳️🌈".codes; codes "🏳️🌈"; # both return 4
Line 1,872:
|-
| <code>lc(''string'')</code>
|[[Perl
|-
| <code>''string''.lc</code>
|[[Raku (programming language)|Raku]]
|-
|<code>tolower(''char'')</code>
Line 1,990:
<syntaxhighlight lang="perl6">
# Example in
"Wiki means fast?".lc; # "wiki means fast?"
</syntaxhighlight>
Line 2,027:
|-
| <code>split ''separator'', ''string'', 2</code> <br /> <code>''string''.split( ''separator'', 2 )</code>
|[[Raku (programming language)|Raku]]
|Separator does not have to be a regular expression
|}
Line 2,038:
<syntaxhighlight lang="perl">
# Examples in Perl 5 /
split /(spam)/, 'Spam eggs spam spam and ham' ,2; # ('Spam eggs ', 'spam', ' spam and ham');
split /(X)/, 'Spam eggs spam spam and ham' ,2; # ('Spam eggs spam spam and ham');
Line 2,095:
|-
| <code>''string''.subst(''find'', ''replace'', :g)</code>
|[[Raku (programming language)|Raku]]
|-
| <code>''string''.replace(''find'', ''replace'', "g") <ref>third parameter is non-standard</ref> or<br /> ''string''.replace(/''find_regex''/g, ''replace'')<ref name="regex" /></code>
Line 2,150:
<syntaxhighlight lang="perl6">
// Examples in
"effffff".subst("f", "jump", :g); # returns "ejumpjumpjumpjumpjumpjump"
"blah".subst("z", "y", :g); # returns "blah"
Line 2,185:
|-
| <code>flip ''string''</code> <br /> <code>''string''.flip</code>
|[[Raku (programming language)|Raku]]
|-
| <code>lists:reverse(''string'')</code>
Line 2,265:
<syntaxhighlight lang="perl6">
# Example in
"hello".flip # returns "olleh"
</syntaxhighlight>
Line 2,311:
|-
| <code>rindex(''string'',''substring''«,''startpos''»)</code> <br /> <code>''string''.rindex(''substring''«,''startpos''»)</code>
|[[Raku (programming language)|Raku]]
|returns Nil
|-
Line 2,411:
<syntaxhighlight lang="perl6">
# Examples in
"Hello mate".rindex("e"); # returns 9
"Hello mate".rindex("e", 4); # returns 1
Line 2,473:
|-
| <code>substr(''string'',*-''n'')</code> <br /> <code>''string''.substr(*-''n'')</code>
|[[Raku (programming language)|Raku]]
|-
| <code>''string''[-''n'':]</code>
Line 2,516:
<syntaxhighlight lang="perl6">
# Examples in
"abcde".substr(*-3); # returns "cde"
"abcde".substr(*-8); # 'out of range' error
Line 2,590:
|-
| <code>split(''separator'', ''string''«, ''limit''»)</code> <br /> <code>''string''.split(''separator'', «''limit''»)</code>
|[[Raku (programming language)|Raku]]
|-
| <code>explode(''separator'', ''string''«, ''limit''»)</code>
Line 2,686:
<syntaxhighlight lang="perl6">
# Examples in
'Spam eggs spam spam and ham'.split(/spam/); # (Spam eggs and ham)
split(/X/, 'Spam eggs spam spam and ham'); # (Spam eggs spam spam and ham)
Line 2,743:
|-
| <code>substr(''string'', ''startpos'', ''numChars'')</code> <br /> <code>''string''.substr(''startpos'', ''numChars'')</code>
|[[
|-
| <code>substr(''string'', ''startpos'' «,''numChars'', ''padChar''»)</code>
Line 2,859:
<syntaxhighlight lang="perl6">
# Examples in
"abc".substr(1, 1); # returns "b"
"abc".substr(1); # returns "bc"
Line 2,904:
|-
| <code>uc(''string'')</code>
|[[Perl
|-
| <code>''string''.uc</code>
|[[Raku (programming language)|Raku]]
|-
|<code>toupper(''char'')</code>
Line 3,010:
<syntaxhighlight lang="perl6">
# Example in
uc("Wiki means fast?"); # "WIKI MEANS FAST?"
"Wiki means fast?".uc; # "WIKI MEANS FAST?"
Line 3,094:
|-
| <tt>''string''.trim</tt>
|[[Raku (programming language)|Raku]]
|-
| <tt>trim(''string'')</tt>
|[[PHP]], [[
|-
| <tt>[''string'' stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]</tt>
Line 3,250:
* <code>[http://perldoc.perl.org/functions/chomp.html chomp]</code> removes the trailing newline character(s) from a string if present. (What constitutes a newline is [http://perldoc.perl.org/perlvar.html $INPUT_RECORD_SEPARATOR] dependent).
In [[
Example:
|