分析lua中的字符串

发布于 2024-12-27 23:05:40 字数 356 浏览 0 评论 0原文

有人会告诉我,如何从变量中的文本

>Hello World
text,1000
text2,200

读取: 1. line - 如果 in line 是 >并且该行的长度不超过 50 个字符,然后读取,如果不是 - 转到下一行 (此检查的一部分是:

if string.sub(tekst, 1, 1) == '>' then
    ...
end

但没有检查行的长度。

下一行 - 通过“,”传递文本,并首先从“,”之前获取文本,然后从“,”之后获取文本到不同的变量(以分析它是脚本的另一部分)

我将非常感激

would somebody tell me, how to from text in variable like:

>Hello World
text,1000
text2,200

read:
1. line - if in line is > and line isn't logner than 50 chars then read, if not - go to next line
(part of this checking is:

if string.sub(tekst, 1, 1) == '>' then
    ...
end

but there is nothing about checking lenght of line.

next lines - impart text by "," and first get text from before "," then get text from after "," to the different vars (to analyse it by another part of script)

I'll be very grateful

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

穿透光 2025-01-03 23:05:40

您并不完全清楚如何处理匹配的字符串(在 > 和行尾之间),因为 read 是通用的,我只是将其放在表格中。

s=[[
>Hello World
text,1000
>A line that is way too long to fit in this small space won't be accepted in the table.
text2,200
>Some text on the last line]]

t={}
for match in s:gmatch('>([^\n]+)') do
    if #match<50 then
        t[#t+1]=match
        print(match)
    end
end

这还取决于字符串中哪些字符代表行结尾。可能性是: \n (UNIX、Mac 和其他正常世界)或 \r\n (Windows)

Your not entirely clear on what to do with the matched string (between > and the end of the line), as read is kind of generic, I just put it in a table.

s=[[
>Hello World
text,1000
>A line that is way too long to fit in this small space won't be accepted in the table.
text2,200
>Some text on the last line]]

t={}
for match in s:gmatch('>([^\n]+)') do
    if #match<50 then
        t[#t+1]=match
        print(match)
    end
end

This depends also on which character(s) represent a line ending in the string. possibilities are: \n (UNIX, Mac, and the rest of the sane world) or \r\n (Windows)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文