English 中文(简体)
图书馆寻找和替换案文的选择
原标题:Lua string library choices for finding and replacing text

我对卢阿方案拟订工作投了新之门,从 p开始,基本上为世界为朋友们打了一小 add。 我探讨从相当大量的平原案文中找到一段案文的各种途径。 我需要从我所需要的案文中提取信息,然后按惯例处理。

案文的说明可以是若干内容,但下文是我们期待的摘录和程序。

-- GSL --
items = ["itemid":"qty" ,"itemid":"qty" ,"itemid":"qty" ,]
-- ENDGSL --

我们想把案文的整整段从围绕案文的可能大块案文中删除,然后删除:

items = ["itemdid":"qty …

我审视了各种方法,看上去看看看看看看看看看上去,看看看看看看看看看看看看看看看看上去。

没有人对解决这一问题的最佳方法提出任何建议?

EDIT:其他问题

根据已接受的答复,I ve稍作改动。

function GuildShoppingList:GUILDBANKFRAME_OPENED()
    -- Actions to be taken when guild bank frame is opened.
    if debug == "True" then self:Print("Debug mode on, guild bank frame opened") end
    gslBankTab = GetCurrentGuildBankTab()
    gslBankInfo = GetGuildBankText(gslBankTab)
    p1 = gslBankInfo:match( %-%- GSL %-%-%s+(.*)%s+%-%- ENDGSL %-%- )
    self:Print(p1)
end

扼杀现在稍微改变了我们所掌握的信息。

{itemid:qty, itemid:qty, itemid:qty, itemid:qty}

现在,这正是第1页所呼吁的。 我需要更新:除去{}的垫子方法,并对每个项目及其关键特性进行调节,这样一米留下。

itemid:qty
itemid:qty
itemid:qty
itemid:qty

然后,我可以单独确定每一条线,并将其放在需要去的地方。

最佳回答

审判

s=[[-- GSL --
items = ["itemid":"qty" ,"itemid":"qty" ,"itemid":"qty" ,]
-- ENDGSL --]]
print(s:match( %-%- GSL %-%-%s+(.*)%s+%-%- ENDGSL %-%- ))

关键可能是,<代码>-是一种模型变式,如果你想要字面上打字,就需要加以引用。 http://www.lua.org/manual/5.1/manual.html#5.4.1“rel=“nofollow”列入《卢阿参考手册》,第5.1章。

Edit: To the additional problem of looping through keys of what is almost an array, you could do 2 things:

无论从关键还是数量上来说,无论从表面上看,还是从表面上看,都会发现:

 p="{1:10, 2:20, 3:30}"
 for id,qty in p:gmatch( (%d+):(%d+) ) do
     --do something with those keys:
     print(id,qty)
 end

或稍微改动地毯,将其评为卢阿表:

 p="{1:10, 2:20, 3:30}"
 p=p:gsub( (%d+): , [%1]= ) -- replace : by = and enclose keys with []
 t=loadstring( return  ..p)() -- at this point, the anonymous function
                              -- returned by loadstring get s executed
                              -- returning the wanted table
 for k,v in pairs(t) do
     print(k,v)
 end

如果钥匙或数量的形式不单纯是累.,那么在模式中加以改变就应当是三维之策。

问题回答

暂无回答




相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签