Total Pageviews

Tuesday, March 25, 2014

ចង់ Select អីមួយអត់?


បើសិនជាតំលៃរបស់ Index ជាលេខ select() នឹងត្រឡប់មកវិញនៅគ្រប់ទាំង arguments បន្ទាប់ពី argument ចំពោះលេខ Index។ បើមិនដូចនេះទេ index គួរតែជា String # ហើយ select() ត្រឡប់មកលេខទាំងអស់សំរាប់ extra arguments ដែលវាទទួល។

Syntax: select (index, …)

Index(តំរូវការ) វាជាលេខ or String ដែល Parameter អាចជាលេខ ដែលជាករណីដែល select() នឹងត្រឡប់គ្រប់ទាំង argument number index។ បើមិនដូចនេះទេ index គួរតែជា String # and select() ដែលត្រឡប់នៅតំលៃ extra arguments ដែលវាទទួល។

សូមមើលកូដះ
-- This example demonstrates how to access individual return values
-- from a function that returns multiple values

print(string.find("hello hello", " hel"))         --> 6  9
print(select(1, string.find("hello hello", " hel"))) --> 6
print(select(2, string.find("hello hello", " hel"))) --> 9 -- This example prints the total number of extra arguments passed to the `select()` function

print(select("#", a,b,c)) --> 3

No comments:

Post a Comment