Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:01:52+00:00 2026-06-04T07:01:52+00:00

Usually for getting table size, the standard table library function # operator works. However

  • 0

Usually for getting table size, the standard table library function # operator works.

However when I make a table which has a string key index, it doesn’t work.

local function addWriterIdListToTable()

        local returnTable = {}
        local requestString = "1234:16 5678:8 9012:1"
        local idList = requestString:split(" ")
        for i,v in ipairs(idList) do
                local oneId = v:split(":")
                returnTable[oneId[1]] = oneId[2]
        end

        for k,v in pairs(returnTable) do
                print (k .. " " .. v)
        end
        print("size of table: " .. #returnTable)

        return returnTable

end

I want to trsnform a string to table.
The function “split” parse a string, split it with parameter as a delimiter, and return as table.

The result of a excution above function like below.

1234 16
9012 1
5678 8
size of table: 0

It shows the content of table exactly as I expected, but its count is not.

Anybody to help me?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:01:53+00:00Added an answer on June 4, 2026 at 7:01 am

    The # operator tells you the highest numeric index in the table. If there are any gaps in the numeric indexing, it may return the highest below the gap. Basically, the # operator only works right if you’re treating your table like a dense array.

    If you actually want to know how many entries are in a table, you’ll need to iterate over it using the pairs() function and count how many items you get.

    function countTableSize(table)
        local n = 0
        for k, v in pairs(table) do
            n = n + 1
        end
        return n
    end
    

    Although I do wonder why you even need to know how many entries are in the table. Typically all you care about is if the table is empty or not, and you can check that by just seeing if next(table) == nil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Usually I tend to install things via the package manager, for unixy stuff. However,
Usually we define iis web sites which allow anonymous authentication to run under the
Usually i write my where statements as WHERE key=@0 then add a param. Now
I'm getting used to Haskell's higher-order functions. Usually I can replace explicit patterns of
I usually use GWT WindowBuilder editor to design my GWT application UI, however I
I am getting to grips with Windows Azure. I usually use NInject as my
I know this is usually done with cookies, but I am getting unpredictable results
I am getting started with an Axis-based web service, written in Java, which will
I have created a table in APEX that has a PK that is incremented
I have been having problems installing programs for a while, Usually getting an error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.