"String length"의 두 판 사이의 차이

잔글 (→‎Bash)
15번째 줄: 15번째 줄:
expr length "hello"
expr length "hello"
# 5
# 5
</source>
==C++==
{{참고|C++ .length()}}
<source lang='cpp'>
#include <iostream>
using namespace std;
int main() {
string str = "abcdef";
cout << str.length() << endl;
// 6
}
</source>
</source>



2019년 1월 14일 (월) 22:10 판


1 Overview

len
length
strlen
  • Definition: length(string) returns an integer number
  • Description: Returns the length of a string (not counting the null terminator or any other of the string's internal structural information). An empty string returns a length of 0.

2 Bash

expr length "hello"
# 5

3 C++

#include <iostream>
using namespace std;
int main() {
	string str = "abcdef";
	cout << str.length() << endl;
	// 6
}

4 C#

"hello".Length;      // returns 5
"".Length;           // returns 0

5 Erlang

string:len("hello"). %  returns 5
string:len("").      %  returns 0

6 Java

"hello".length()   // returns 5
"".length()        // returns 0

7 JavaScript

var txt = "Hello World!";
var len = txt.length; // 12

8 Lua

("hello"):len() -- returns 5
#"" -- returns 0

9 Objective-C

[@"hello" length]   // returns 5
[@"" length]        // returns 0

10 Perl

length("hello");     #  returns 5
length("");          #  returns 0

11 PHP

strlen('hello');     //  returns 5
strlen('');          //  returns 0

12 Python

len('hello')     #  returns 5
len('')          #  returns 0

13 Ruby

print 'hello'.length
# 5
print ''.length
# 0

14 SQL

14.1 MySQL

SELECT LENGTH( "hello" )
-- 5

15 VB

Len("hello")         '  returns 5
Len("")              '  returns 0

16 같이 보기

17 References