1 Overview[ | ]
- left
- Definition: left(string,n) returns string
- Description: Returns the left n part of a string. If n is greater than the length of the string then most implementations return the whole string (exceptions exist - see code examples).
2 Bash[ | ]
Bash
Copy
input="Hello world"
output=${input:0:4}
echo $output
# Hell
3 POSIX Shell[ | ]
Bash
Copy
input="Hello world"
output=`echo $input | cut -c 1-4`
echo $output
# Hell
4 EXCEL[ | ]
PHP
Copy
=LEFT("abcde", 3)
// abc
=LEFT("abcde", 8)
// abcde
=LEFT("안녕하세요", 2)
// 안녕
=LEFT("안녕하세요")
// 안
5 Java[ | ]
Java
Copy
String str = "Hello";
String a = StringUtils.left(str, 2);
6 JavaScript[ | ]
JavaScript
Copy
str = "Hello";
console.log( str.substr( 0, 2 ) ); // He
console.log( str.substring( 0, 2 ) ); // He
JavaScript
Copy
String.prototype.left = function(n) {
return this.substring(0, n);
}
document.write("hello".left(2)); // he
7 PHP[ | ]
PHP
Copy
substr("abcde", 0, 3) // returns "abc"
substr("abcde", 0, 8) // returns "abcde"
8 Perl[ | ]
Perl
Copy
print substr "abcde", 0, 3 . "\n"; # returns "abc"
print substr "abcde", 0, 8 . "\n"; # returns "abcde"
9 Rexx[ | ]
PHP
Copy
left("abcde", 3) /* returns "abc" */
left("abcde", 8) /* returns "abcde " */
left("abcde", 8, "*") /* returns "abcde***" */
10 Scheme[ | ]
scheme
Copy
(use-modules (srfi srfi-13))
(string-take "abcde", 3) ; returns "abc"
(string-take "abcde", 8) ; error
11 Windows Batch[ | ]
batch
Copy
set input=Hello World
set output=%input:~0,4%
echo %output%
REM Hell
12 SQL[ | ]
12.1 MySQL[ | ]
sql
Copy
SELECT LEFT("hello world", 3);
-- hel
12.2 Oracle[ | ]
- Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
sql
Copy
rpad('hello', 7);
--returns 'hello '
rpad('hello', 4);
--returns 'hell'
rpad('hello', 7, 'x');
--returns 'helloxx'
rpad('hello', 4, 'x');
--returns 'hell'
sql
Copy
select rpad('hello', 10, 'abc') from dual;
--returns 'helloabcab'
13 VB[ | ]
vbnet
Copy
Left("sandroguidi", 3)
' returns "san"
Left("sandroguidi", 100)
' returns "sandroguidi"
14 같이 보기[ | ]
15 References[ | ]
편집자 Jmnote Ykhwong Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
HTML textarea 자동 높이 조절 ― …JavaScript 랜덤 한글 ― JmnoteJavaScript 랜덤 한글 ― JmnoteJavaScript 랜덤 한글 ―Pinkcrimson
JavaScript 랜덤 한글 ― MywikierJavaScript 변수 ― Nathan on zetawikiJavaScript 변수 ― John JeongJavaScript 변수 ― SotoZeroClipboard 사용하기 ― LilisZeroClipboard 사용하기 ― Jmnote자바스크립트 HTML 테이블 행 추가/삭제 ― Pilming자바스크립트 HTML 테이블 행 추가/삭제 ― Jmnote자바스크립트 웹페이지 읽기 ― …