本文介绍了从URL获取参数,在查询字符串中获取子字符串并将其存储在表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取URL中某些参数的值,我知道这个主意,但不知道如何获取它们.
I want to get the values of some parameters in a URL, I know the idea but I don't know how to do get them.
我有一个URL字符串:
I have an string that is an URL:
local url="fbconnect://success?to[0]=213322147507203&to[1]=223321147507202&request=524210977333164"
我想检测子字符串"to ["并获取数字293321147507203、293321147507202并将它们存储在表中.
I want to detect the sub-strings "to[" and get the numbers 293321147507203,293321147507202 and store them in a table.
我知道该过程是检测子字符串to [,然后获取为3个字符的子字符串(或6不确定是否从"to ["开头开始计数,然后获取数字,始终为15位数字.
I know the process is detect the sub-string to[ and then get the sub-string that is 3 character (or 6 not sure if it counts from the beginning of "to[" and then get the number, always is a 15 digit number.
推荐答案
local url="fbconnect://success?to[0]=213322147507203&to[1]=223321147507202&request=524210977333164"
local some_table = {}
for i, v in url:gmatch'to%[(%d+)]=(%d+)' do
some_table[tonumber(i)] = v -- store value as string
end
print(some_table[0], some_table[1]) --> 213322147507203 223321147507202
这篇关于从URL获取参数,在查询字符串中获取子字符串并将其存储在表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!