string - 来自链接/URL 的 Dart 子字符串
问题描述
我试图26189-abstract-color-background.jpg
从这个字符串中获取
void main() {
//? link string
String s = "http://www.exampleSite.com/files/146/26189-abstract-color-background.jpg?666ff";
// s = s.substring(s.lastIndexOf("/")+1);
String s1 = s.substring(s.indexOf('') - 2);
print(s1);
}
解决方案
使用Uri.parse()
和pathSegments
void main() {
String s = "http://www.exampleSite.com/files/146/26189-abstract-color-background.jpg?666ff";
var uri = Uri.parse(s);
print(uri.pathSegments.last);
}
推荐阅读
- python - 如何在熊猫中组合数据框选择查询?
- java - Amazon Lambda GET 请求、Amazon API 网关、空查询参数
- c# - Discord.NET 如何通过一个命令给每个人一个角色?
- java - 为什么 VOLLEY 检索具有不同参数的相同数据?
- java - 在多线程中的java中工作的同步块
- java - 如何提高 Java 中的 StAX xml 解析器速度?
- java - 如何仅使用现有 webdriver 会话的会话 ID 或 cookie 获取 webdriver 对象
- postgresql - 正在寻找在 AWS Aurora DB 中运行的 Postgres 数据库之间同步数据的解决方案(可能是 pgsync?)
- html - 如何垂直居中一组动画div的起点
- azure - 我在 Azure Active Directory 中失去了管理员访问权限。我应该怎么办?