함수 rtrim()

Jmnote (토론 | 기여)님의 2015년 2월 19일 (목) 12:19 판 (→‎Cmd)

1 개요

right trim
rtrim
TrimEnd
C
Copy
output = rtrim(input)
  • input
text
Copy
"\t  hello  \n"
  • output
text
Copy
"\t  hello"

2 C#

C#
Copy
string input = "\t  hello  \n";
string output = input.TrimEnd();
// returns "\t  hello"

3 Cmd

bat
Copy
set my_name=      John Smith        &rem
set trimmed=%my_name%
IF "%trimmed:~-32%"=="                                " set trimmed=%trimmed:~0,-32%
IF "%trimmed:~-16%"=="                " set trimmed=%trimmed:~0,-16%
IF "%trimmed:~-8%"=="        " set trimmed=%trimmed:~0,-8%
IF "%trimmed:~-4%"=="    " set trimmed=%trimmed:~0,-4%
IF "%trimmed:~-2%"=="  " set trimmed=%trimmed:~0,-2%
IF "%trimmed:~-1%"==" " set trimmed=%trimmed:~0,-1%
echo [%my_name%]
echo [%trimmed%]
REM [      John Smith        ]
REM [      John Smith]

4 JavaScript

JavaScript
Copy
String.prototype.rtrim = function() {
  return this.replace(/\s+$/,'');
}

var input = "\t  hello  \n";
var output = input.rtrim();
JavaScript
Copy
function rtrim() {
  return this.replace(/\s+$/,'');
}

var input = "\t  hello  \n";
var output = rtrim(input);

5 PHP

PHP
Copy
$input = "\t  hello  \n"; 
$output = rtrim($input );
PHP
Copy
$input = "\t  hello  \n"; 
$output = chop($input ); // alias

6 Python

Python
Copy
trimmed = "\t  hello  \n".rstrip() # returns "hello"

7 Ruby

Ruby
Copy
trimmed = "\t  hello  \n".rstrip # returns "hello"

8 SQL

8.1 MySQL

MySQL
Copy
SELECT RTRIM( "  hello world  " );
-- "  hello world"

9 같이 보기