android - 如何检查 Uri 数据是否包含一些单词,然后在 webview 中替换它?
问题描述
我首先检查 Uri 数据是否包含 ad,然后我想将 ad 替换为 as 如何将 ad 替换为 as。
@Override
protected void onStart() {
super.onStart();
Intent intent = getIntent();
Uri data = intent.getData();
//want to check contains in data and if contains i want to replace it
if(data.contains("ad")){
data.replace("ad", "as");
}
try {
webView.loadUrl(data.toString());
}
catch (Exception e){
e.printStackTrace();
}
}
解决方案
Uri 没有contains
and replace
,因此您必须先转换为String
。
试试这个:
if (data != null) {
String uriString = data.toString();
if (uriString.contains("ad")) {
uriString = uriString.replace("ad", "as");
}
try {
webView.loadUrl(uriString);
}
catch (Exception e){
e.printStackTrace();
}
}
推荐阅读
- python - Jupyter / IPython SList ::从shell执行运算符“!”获取非标记化输出
- python-3.x - “无效的继续字节” Python Socket
- powershell - 通过 Powershell 更改服务帐户密码给我错误 1609 但密码正确
- javascript - DELETE前如何处理OPTIONS方法?
- ios - 超出范围,线程问题
- sql - 是否可以在 Oracle SQL 中仅使用连接而不是使用 connect by 子句来编写分层查询
- amazon-web-services - 运行完全相同的查询时,Athena 返回不同的结果集
- python - 使用 str.contians 查看列表中的哪些单词在每个项目中
- python - 使用 PyAV 将视频直接读入 Numpy(无迭代)
- arduino - ArduinoHttpClient 不会发布 json