zoukankan      html  css  js  c++  java
  • The Length Operator(井符号) 和 string.len操作符

    2.5.5 – The Length Operator(#)

    The length operator is denoted by the unary(一元的) operator #. The length of a string is its number of bytes (that is, the usual meaning of string length when each character is one byte). The length of a table t is defined(定义) to be any integer(整数) index n such that t[n] is not nil and t[n+1] is nil; moreover, if t[1] is nil, n can be zero. For a regular array(数组), with non­nil values from 1 to a given n, its length is exactly that n, the index of its last value. If the array has "holes" (that is, nil values between other nonnil values), then #t can be any of the indices(指数) that directly precedes(领先) a nil value (that is, it may consider any such nil value as the end of the array(数组)).

    string.len (s)
    Receives a string and returns its length. The empty string "" has length 0. Embedded zeros are counted, so
    "a00bc00" has length 5.


    示例:

    local x = "string"
    local tableDemo = {
        "helloworld",
        "appp",
        nil,  --holes
        "app",
        "appx",
        nil,  --holes
        'x'
    }
    
    print(#x)
    print(#tableDemo)
    
    print(string.len(x))
    -- print(string.len(tableDemo))
  • 相关阅读:
    A1020 Tree Traversals [中序后序建树]
    bfs 找步数最少的迷宫路径
    hdu 1241
    hdu 素数环
    A1054 The Dominant Color [map]
    A1097 Deduplication on a Linked List [链表去重]
    C# 中Dictionary的用法及用途
    C#文件操作
    C# 属性概述
    C# Lock的用法
  • 原文地址:https://www.cnblogs.com/dotdog/p/4513766.html
Copyright © 2011-2022 走看看