"함수 right()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-==참고 자료== +==참고==))
잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 8개는 보이지 않습니다)
2번째 줄: 2번째 줄:
==Bash==
==Bash==
[[category: Bash]]
[[category: Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
input="Hello world"
input="Hello world"
output=${input:(-3)}
output=${input:(-3)}
echo $output
echo $output
# rld
# rld
</source>
</syntaxhighlight>
 
==POSIX Shell==
<syntaxhighlight lang='bash'>
input="Hello world"
output=`echo $input | rev | cut -c 1-3 | rev`
echo $output
# rld
</syntaxhighlight>


==Excel==
==Excel==
[[category: Excel]]
[[category: Excel]]
<source lang='php'>
<syntaxhighlight lang='php'>
=RIGHT("Hello", 2)
=RIGHT("Hello", 2)
// lo
// lo
23번째 줄: 31번째 줄:
=RIGHT("안녕하세요")
=RIGHT("안녕하세요")
// 요
// 요
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[category: JavaScript]]
[[category: JavaScript]]
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
console.log( str.substr( -2 ) ); // lo
console.log( str.substr( -2 ) ); // lo
console.log( str.substring( str.length-2, str.length ) ); // lo
console.log( str.substring( str.length-2, str.length ) ); // lo
console.log( str.substring( str.length-2, 9999 ) ); // lo
console.log( str.substring( str.length-2, 9999 ) ); // lo
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang="php">
<syntaxhighlight lang="php">
echo substr("hello", -3);    // shows "llo"
echo substr("hello", -3);    // shows "llo"
echo substr("hello", -3, 2);    // shows "ll"
echo substr("hello", -3, 2);    // shows "ll"
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
function utf8_substr($str, $start, $len=-1) {
function utf8_substr($str, $start, $len=-1) {
if($len==-1)$len = mb_strlen($str, 'UTF-8')-$start;
if($len==-1)$len = mb_strlen($str, 'UTF-8')-$start;
45번째 줄: 53번째 줄:
}
}
echo utf8_substr('안녕하세요', -3); // 하세요
echo utf8_substr('안녕하세요', -3); // 하세요
</source>
</syntaxhighlight>
 
==Perl==
[[category: Perl]]
<syntaxhighlight lang="perl">
print substr("hello", -3) . "\n"; # shows "llo"
print substr("hello", -3, 2) . "\n"; # shows "ll"
</syntaxhighlight>
 
==R==
[[분류: R]]
<syntaxhighlight lang='r'>
s <- "hello"
substr(s, nchar(s)+1-3, nchar(s))
## [1] "llo"
</syntaxhighlight>
<syntaxhighlight lang='r'>
right <- function(s, n){
  substr(s, nchar(s)-n+1, nchar(s))
}
right("hello", 3)
## [1] "llo"
</syntaxhighlight>


==SQL==
==SQL==
51번째 줄: 81번째 줄:
===MySQL===
===MySQL===
[[category: MySQL]]
[[category: MySQL]]
<source lang='sql'>
<syntaxhighlight lang='sql'>
SELECT RIGHT("hello world", 3);
SELECT RIGHT("hello world", 3);
-- rld
-- rld
</source>
</syntaxhighlight>


==VB==
==VB==
[[category: VB]]
[[category: VB]]
<source lang='VB'>
<syntaxhighlight lang='VB'>
Right("hello", 3) ' retruns "llo"
Right("hello", 3) ' retruns "llo"
</source>
</syntaxhighlight>
 
== Windows Batch ==
<syntaxhighlight lang='batch'>
set input=Hello World
set output=%input:~-3%
echo %output%
REM rld
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:36 기준 최신판

1 Bash[ | ]

input="Hello world"
output=${input:(-3)}
echo $output
# rld

2 POSIX Shell[ | ]

input="Hello world"
output=`echo $input | rev | cut -c 1-3 | rev`
echo $output
# rld

3 Excel[ | ]

=RIGHT("Hello", 2)
// lo

=RIGHT("Hello", 8)
// Hello

=RIGHT("안녕하세요", 3)
// 하세요

=RIGHT("안녕하세요")
// 요

4 JavaScript[ | ]

console.log( str.substr( -2 ) ); // lo
console.log( str.substring( str.length-2, str.length ) ); // lo
console.log( str.substring( str.length-2, 9999 ) ); // lo

5 PHP[ | ]

echo substr("hello", -3);    // shows "llo"
echo substr("hello", -3, 2);    // shows "ll"
function utf8_substr($str, $start, $len=-1) {
	if($len==-1)$len = mb_strlen($str, 'UTF-8')-$start;
	return mb_substr($str, $start, $len, 'UTF-8');
}
echo utf8_substr('안녕하세요', -3); // 하세요

6 Perl[ | ]

print substr("hello", -3) . "\n"; # shows "llo"
print substr("hello", -3, 2) . "\n"; # shows "ll"

7 R[ | ]

s <- "hello"
substr(s, nchar(s)+1-3, nchar(s))
## [1] "llo"
right <- function(s, n){
  substr(s, nchar(s)-n+1, nchar(s))
}
right("hello", 3)
## [1] "llo"

8 SQL[ | ]

8.1 MySQL[ | ]

SELECT RIGHT("hello world", 3);
-- rld

9 VB[ | ]

Right("hello", 3) ' retruns "llo"

10 Windows Batch[ | ]

set input=Hello World
set output=%input:~-3%
echo %output%
REM rld

11 같이 보기[ | ]

12 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}