我有这样的字符串:
输入:
val s1: String = "my.mail.google.com.xxx.hello.google.com"
val s2: String = "google.com"
输出:
val s3: String = "my.mail.google.com.xxx.hello"
目前,我这样做:
s1.stripSuffix(s".$s2")
从 s1 中删除 s2 以便获得 s3 的最有效解决方案是什么? 有比我更快的解决方案吗?我可以用 substring 以某种方式解决它吗?会更快吗?
编辑: 我每秒流式传输 10^6 条消息,我确实对这些数据应用了这样的函数,所以性能对我来说很重要。