함수 right()

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 }}