如何将 Lua 中的列表转换为 Kotlin?
2021-12-16 19:47:38
收藏:0
阅读:242
评论:1
我正在一个最初从 Lua 开始的项目上工作,并希望将其更新到 Kotlin。
我有大约 5000 个类似以下形式的问题/答案:
['Question'][1] = "'7x' 是哪种饮料的秘密成分?";
['Answers'][1] = {"可口可乐"};
['Question'][2] = "'And the big wheel keep on turning neon burning up above and I'm just high on the world come on and take the low ride with me girl on the.....' 这首 Dire Straits 歌曲的歌名是什么?";
['Answers'][2] = {"爱的隧道"};
我想重新格式化这些问题,而不是手动查看所有 5000 个问题,以便它们看起来像这样:
val que1 = Question(
1, "'7x' 是哪种饮料的秘密成分?",
"可口可乐"
)
val que2 = Question(
2, "'And the big wheel keep on turning neon burning up above and I'm just high on the world come on and take the low ride with me girl on the.....' 这首 Dire Straits 歌曲的歌名是什么?",
"爱的隧道"
)
请帮助我找出如何重新格式化这些问题/答案。谢谢。
原文链接 https://stackoverflow.com/questions/70373490
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
- 如何编写 Lua 模式将字符串(嵌套数组)转换为真正的数组?
你可以编写类似这样的脚本来获取所需的输出。
步骤1:创建
input.txt
并在其中粘贴您想要翻译的 lua 代码。['Question'][1] = "'7x' was used to refer to the secret ingredient of what drink"; ['Answers'][1] = {"coca cola"}; ['Question'][2] = "'And the big wheel keep on turning neon burning up above and I'm just high on the world come on and take the low ride with me girl on the.....' What's the Dire Straits song title?"; ['Answers'][2] = {"tunnel of love"};
步骤2:创建一个名为
output.txt
的空文件。此文件将包含转换后的代码。步骤3:运行此
main
函数。您可能需要根据您的目录结构修改文件路径。注意:此代码是用Kotlin
编写的。fun main() { val input = File("src/main/kotlin", "input.txt").readLines() val outputWriter = File("src/main/kotlin", "output.txt").printWriter() val lines = input.windowed(2, 2) val questions = mutableListOf<String>() lines.forEachIndexed { index, str -> val que = str[0].split("\"")[1] val ans = str[1].split("\"")[1] val question = "val que${index + 1} = Question(${index + 1}, \"$que\", \"$ans\")" println(question) questions.add(question) } outputWriter.use { out-> questions.forEach { out.println(it) } } }
运行脚本后,您将在
output.txt
中获得所需的输出。或者,您也可以从控制台中获取输出。