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 760063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:40:18+00:00 2026-05-14T15:40:18+00:00

Suppose I am inserting a string into a table as follows: table.insert(tbl, mystring) and

  • 0

Suppose I am inserting a string into a table as follows:

table.insert(tbl, mystring)

and that mystring is generated by replacing all occurrences of “a” with “b” in input:

mystring = string.gsub(input, "a", "b")

The obvious way to combine the two into one statement doesn’t work, because gsub returns two results:

table.insert(tbl, string.gsub(input, "a", "b"))  -- error!
-- (second result of gsub is passed into table.insert)

which, I suppose, is the price paid for supporting multiple return values. The question is, is there a standard, built-in way to select just the first return value? When I found select I thought that was exactly what it did, but alas, it actually selects all results from N onwards, and so doesn’t help in this scenario.

Now I know I can define my own select as follows:

function select1(n, ...)
  return arg[n]
end

table.insert(tbl, select1(1, string.gsub(input, "a", "b")))

but this doesn’t look right, since I’d expect a built-in way of doing this.

So, am I missing some built-in construct? If not, do Lua developers tend to use a separate variable to extract the correct argument or write their own select1 functions?

  • 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-05-14T15:40:19+00:00Added an answer on May 14, 2026 at 3:40 pm

    You can surround the expression by parentheses:

    table.insert(tbl, (string.gsub(input, "a", "b")))
    

    This will select only the first result.

    To get the nth result, you can use select and surround it by parentheses:

    func1( (select(n, func2())) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 534k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is right resolution which helps: RESOLUTION!! <compilation batch="false" debug="false"… May 17, 2026 at 12:52 am
  • Editorial Team
    Editorial Team added an answer Strange thing is: you already know the answer since you've… May 17, 2026 at 12:51 am
  • Editorial Team
    Editorial Team added an answer It seems the same question as I answerd before. You… May 17, 2026 at 12:51 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Suppose I have one string list may have duplicated items: A B C A
Suppose you have a table where you store the musical preferences of people, and
I want to represent the list hi, hello, goodbye, good day, howdy (with that
I have a table with a field which contains strings in my MySQL database.
I'm having trouble inserting a block of text when a certain condition is met
This question concerns XML schemas and files. Suppose I am developing a desktop application
I have a view that has a custom ArrayAdapter as a ListAdapter. Customer is
I have some files on my computer that are in UTF-16, though this seems
Longtime Eclipse user here; I recently discovered the Block Selection Mode (Alt-Shift-A) that was
I'm using Envers to audit different fields of my entities. The framework works in

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.