Lua code - System testget("#349") -- table functions
-- an example text (taken from #523)
text = [[
get("#515") -- splitLines
text = getSnippet("#2000025")
lines = splitLines(text)
header = lines[1]:gsub(" +", " "):gsub("^ ", ""):gsub(" $", "")
print(header)
]]
function findReferences(text)
refs = {}
for word in text:gmatch("#%d+") do
refs[word] = true
end
return keystolist(refs)
end
refs = findReferences(text)
table.sort(refs)
s = table.concat(refs, " ")
print(s)
assert(s == "#2000025 #515")
return truetest run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
| ID | Author/Program | Comment | Date | |
|---|---|---|---|---|
| 685 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { get("#349") -- table functions -- an example text (taken from #523) text = [[ get("#515") -- splitLines text = getSnippet("#2000025") lines = splitLines(text) header = lines[1]:gsub(" +", " "):gsub("^ ", ""):gsub(" $", "") print(header) ]] function findReferences(text) refs = {} for word in text:gmatch("#%d+") do refs[word] = true end return keystolist(refs) end refs = findReferences(text) table.sort(refs) s = table.concat(refs, " ") print(s) assert(s == "#2000025 #515") return true }} | 2015-08-19 08:28:29 | delete |
| 683 | #1000604 (pitcher) | 2015-08-18 00:07:22 |
| Snippet ID: | #524 |
| Snippet name: | Find snippet references in a text |
| Eternal ID of this version: | #524/1 |
| Text MD5: | 51bea7bb12e5ed575e36a3a9a17ccf71 |
| Author: | stefan |
| Category: | |
| Type: | Lua code - System test |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-03-12 17:47:12 |
| Source code size: | 530 bytes / 27 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 1387 / 242 |
| Referenced in: | [show references] |