android - 制作切割字符串android的算法
问题描述
我收到了一个电车(字符串内容一些信息(产品和价格),例如“/tomatos*500/botot*1200/tor*1200”),我需要将该字符串剪切成 ArrayList 和产品内容(字符串产品, 字符串价格)。
这是一个数据样本
"/香蕉*200 /西红柿*7850 /福尔福尔*10 /鸡蛋*1200 /猕猴桃*100 "
我试过这个算法:
String[] decouped_product = post.toString().split("/");
for(int i = 0 ; i <decouped_product.length;i++){
Log.d("decoupage1",decouped_product[i]);
if(decouped_product[i].equals("")){
}else {
String[] decouped_prix = post.toString().split("\\*");
String Product_nom = decouped_prix[0];
String Prix = decouped_prix[1];
Log.d("nom: ",Product_nom);
Log.d("prix: ",Prix);
}
}
Log.d("changed file",post.toString());
但它不起作用它给了我
别名:西红柿
价格:*500/botot
类似的东西。但我希望它像:
别名:西红柿
价格:500
名词:底
价格:1200
名词:托
价格:1200
解决方案
解决方案是:
String[] decouped_product = post.toString().split("/");
for(int i = 0 ; i <decouped_product.length;i++){
Log.d("decoupage1",decouped_product[i]);
if(decouped_product[i].equals("")){
}else {
String[] decouped_prix = decouped_product[i].toString().split("\\*");
String Product_nom = decouped_prix[0];
String Prix = decouped_prix[1];
Log.d("nom: ",Product_nom);
Log.d("prix: ",Prix);
}
}
Log.d("changed file",post.toString());
推荐阅读
- python - sampled_softmax_loss 如何从 softmax 嵌入矩阵中知道要使用哪个嵌入?
- python - 合并数据框
- typescript - 如何在离子列表中添加广告横幅
- circleci - CircleCi 2.0 在子目录中使用项目
- c++ - dlopen(RTLD_NOLOAD) 在 dlclose 之后仍然返回不为空
- python - 来自不同文本编辑器的 Python 转换
- spring - 如何在 Thymeleaf 中使用默认常量作为 url 超链接?
- android - 使用自定义相机拍照时出现 RuntimeException - “takePicture failed”
- c# - WPF双重动画无法正常工作C#
- apache-flink - 为什么在 Flink 中使用 reduce 运算符时得到 2 项