String after encoding and array length doubts

Source: Internet
Author: User

1. Java:
String length:

str = "abcdefg";int len = str.length(); // 7String strcn = "你好世界";int len = str.length(); // 4
    • 1
    • 2
    • 3
    • 4
    • 1
    • 2
    • 3
    • 4

Number of arrays:

String[] arr = new String[3];int arrlen = arr.length;    // 3
    • 1
    • 2
    • 1
    • 2

2. PHP
String length:

$str =' Hello World ';$strlen = strlen ( $STR);  $STRCN =  ' Hello World ';  $STRCN); //a Chinese is 3 string number  $strcnlen 2 = Mb_strlen (  $STRCN,  ' utf-8 '); //put a Chinese as a string number print  $strlen. //11print  $strcnlen. //12print  $strcnlen 2.//4             
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

Number of arrays:

Tip:sizeof () equals count ()$arr =Array' A ',' C ',' B ' + =Array1,2), ' d ' =>array (1, 2,3)); //calculates the number of one-dimensional arrays  $arrlen = count ($ ARR); //or Count ($arr, 0) or count ($arr, count_normal) //calculates the total number of multidimensional arrays Span class= "hljs-variable" > $arrlen 1 = count ( $arr, 1); //or COUNT ($arr, count_recursive) print  $arrlen. //4print  $arrlen 1.//9             
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

3. Python:
String length:

‘hello world‘strcn = ‘你好世界‘strlen = len(str)strcnlen = len(strcn)print strlen // 11print strcnlen // 12
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

Number of arrays:

arr = [1,2,3,4,5]strlen = len(arr)print strlen // 5
    • 1
    • 2
    • 3
    • 1
    • 2
    • 3

4, JS
String length:

var txt="Hello World"document.write(txt.length)  // 11var txt="你好世界"document.write(txt.length)  // 4
    • 1
    • 2
    • 3
    • 4
    • 5
    • 1
    • 2
    • 3
    • 4
    • 5

Number of arrays:

var arr = [‘a‘, 2, ‘c‘];document.write(arr.length) // 3
    • 1
    • 2
    • 1
    • 2

String after encoding and array length doubts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.