kotlin - 如何高效解析?
问题描述
假设我要解析以下字符串:“01:12 Joseph We will have a meeting at 6 PM.”。在 CI 中可以做(伪代码):
struct data {
char *time;
char *name;
char *message;
};
char *string = "01:12 Joseph We will have a meeting at 6 PM."
struct data notification;
notification.time = strtok(string, " ");
notification.name = strtok(NULL, " ");
notification.message = strtok(NULL, " ");
puts(notification.time); // prints the time it was sent
puts(notification.name); // prints the name of the sender
puts(notification.message); // prints the message content
请注意,我仍在使用相同的缓冲区,我认为这是使用 kotlin 的最佳方式。现在的问题是,将所有数据留在同一个缓冲区中更好还是创建一个新对象用于时间,另一个用于名称,另一个用于消息?
您应该将此视为不断出现的新通知流,您必须解析每个通知以便将其定位在窗口内的任何位置,这对于聊天应用程序等很有用。因此,对于这种用例来说,这是最好的。
解决方案
推荐阅读
- php - 在自定义管理菜单项中声明和使用全局变量
- html - CSS:你能用 flexbox 实现列数吗?
- ios - SwiftUI:如何将视图作为参数传递给另一个视图以获取底页?
- google-bigquery - BigQuery 将新列插入(不附加)到架构中
- javascript - SyntaxError: Unexpected token then used @storybook/addon-storyshots
- sql - 在雪花的临时表中计算大小写
- apache-kafka - Strimzi 主题运算符不工作 - Openshift
- node.js - 将 socket.io 与 express.js 控制器一起使用
- c# - 当 HttpContext.Request.HasFormContentType = true 时 HttpContext.Request.Form.Keys 为空
- sql-server - 尝试在 linux mssql server 2019 中运行 polybase 查询时,是什么导致“尚未连接远程 Java 桥”?