kotlin - Kotlin 字符串替换
问题描述
如何替换kotlin中的字符串?我在这里有 html 字符串的示例。
var test = "<html><body><p> just some test text</p> And i wanna use this text for texting and i ll show you this image https://www.instagram.com/p/B8I9_KiF45g/?utm_source=ig_web_copy_link also this is the instagram photo with just normal link id body https://www.instagram.com/p/B8I3r66pVpp/ <h> random title text </h></body></html>"
是否可以选择在 < iframe> 标签中仅添加 instagram 链接,在链接末尾添加“嵌入”字符串,因此输出将如下所示:
"<html><body><p> just some test text</p> And i wanna use this text for texting and i ll show you this image <iframe src="https://www.instagram.com/p/B8I9_KiF45g/embed"> </iframe> also this is the instagram photo with just normal link id body <iframe src="https://www.instagram.com/p/B8I3r66pVpp/embed" </iframe> <h> random title text </h></body></html>"
解决方案
我会用特定库(如DOMParser-kotlin)解析 html 字符串,然后循环查找 iframe 并修改 src 属性
推荐阅读
- r - 如何抑制 RCurl 的 curlPerform 的输出?
- algorithm - 使用位操作编程问题查找子序列
- android - 谷歌地图 StackOverflowError 崩溃
- react-native - 使用 onpress 在屏幕之间导航
- json - 解析对打字稿类的json响应
- java - actionPerformed(ActionEvent e) 的正确语法是什么?
- octave - 使用 Octave 脚本的字符模式(shell/ASCII)绘图
- java - 在片段之间传递可变数据时出现 NullPointerException
- excel - 比较交错日期
- wordpress - 设置 postdata 不适用于未找到的帖子