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

65번째 줄: 65번째 줄:
[[category: jQuery]]
[[category: jQuery]]
<source lang='javascript'>
<source lang='javascript'>
var trimmed = $.trim(" HELLO ");
var trimmed = $.trim(" HELLO ");
</source>
</source>



2015년 2월 9일 (월) 22:39 판

trim
strip

1 Bash

STR="  Hello, World  "
echo "[$STR]"  # [  Hello, World  ]
TRIMMED=`echo $STR`
echo "[$TRIMMED]"  # [Hello, World]

2 Cmd

set str=  Hello  
echo [%str%]
for /f "tokens=* delims= " %a in ("%str%") do set str=%a
echo [%str%]
REM [  Hello  ]
REM [Hello   ]

3 C#

string str = "  HELLO  ";
string trimmed = str.Trim();

4 Excel

=TRIM("  HELLO  ")
// returns 'HELLO'

5 Java

String str = "  HELLO  ";
String trimmed = str.trim();

6 JavaScript

function trim(str) {
 return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

var str = "  HELLO  ";
var trimmed = trim(str);
String.prototype.trim=function(){return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');};

var str = "  HELLO  ";
var trimmed = str.trim();

7 jQuery

var trimmed = $.trim("  HELLO  ");

8 Objective-C

NSString *str = @"  HELLO  ";
NSString *trimmed = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

9 PHP

$trimmed = trim("\t  hello  \n"); // returns "hello"

10 Python

trimmed = "\t  hello  \n".strip() # returns "hello"

11 Ruby

trimmed = "\t  hello  \n".strip # returns "hello"

12 SQL

12.1 MySQL

SELECT TRIM('  hello world  ');
SELECT TRIM("  hello world  ");
-- hello world

12.2 Oracle

LTRIM(RTRIM(" hello "));

13 같이 보기