java - 从样本列表中获取项目
问题描述
我有这个字符串列表:
[InstagramUserSummary(
super = Summary@a4acf205,
is_verified = false,
profile_pic_id = 1773528799482591987_1654599017,
is_favorite = false,
is_private = false,
username = ququletta,
pk = 1654599017,
profile_pic_url = https://instagram.fada1-5.fna.fbcdn.net/vp/8d99014623ed527e52512a20002d884b/5C387E45/t51.2885-19/s150x150/31203725_200759604054857_5778864946146181120_n.jpg,
has_anonymous_profile_picture = false,
full_name = Ququletta
)]
我只想获取用户名=
这个有可能?
解决方案
是的,我猜你正在使用 JAVA。此代码将获得“ququletta”值
String stringValue = "[InstagramUserSummary(super=dev.niekirk.com.instagram4android.requests.payload.InstagramUserSummary@a4acf205, is_verified=false, profile_pic_id=1773528799482591987_1654599017, is_favorite=false, is_private=false, username = ququletta, pk=1654599017, profile_pic_url=https://instagram.fada1-5.fna.fbcdn.net/vp/8d99014623ed527e52512a20002d884b/5C387E45/t51.2885-19/s150x150/31203725_200759604054857_5778864946146181120_n.jpg, has_anonymous_profile_picture=false, full_name=Ququletta)]";
// First remove all white spaces
stringValue = stringValue.replaceAll(" ", "");
// Find where the username key begins
int beginIndex = stringValue.indexOf("username");
// Find where the username value ends
int endIndex = stringValue.indexOf(",", beginIndex);
// Subtract the username key and value
String usernameValue = stringValue.substring(beginIndex, endIndex);
// Get the username value
System.out.println(usernameValue.split("=")[1]);
推荐阅读
- c++ - 向后的 cpp 无法再构建,尽管链接仍然缺少 lbdf
- python - 如何从网站中提取信息?
- ios - 如何使用自动布局放置 CAPSPageMenu
- html - 最佳实践。
或
,或, 等等 - python - 如何从不同的相关列中选择合适的行?(熊猫数据框)
- r - 您可以使用 r 将日期四舍五入到 1 日或 15 日吗?
- ios - 在横向模式下隐藏 NavigationView 栏并在 SwiftUI 中延迟隐藏
- c++ - 如何方便地构造一个指向具有单个元素的向量的 unique_ptr?
- php - 在 Laravel 上找不到类 - Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
- git - git repquest 中止“您对以下文件的本地更改将被合并覆盖”