从字符串java中检索值的最佳方法 [英] Best way to retrieve a value from a string java
问题描述
如果我传递的字符串包含逗号分隔的键值对,则
If I am being passed a string that contains comma delimited key-value pairs like this
seller = 1000,country =canada ,address =123 1st st
等等。
似乎必须有一种比解析然后迭代更好的方法。
There seems like there must be a better way than parsing then iterating through.
根据Java中的密钥名称从此字符串中检索值的最佳方法是什么?
What is the best way to retreive a value from this string based on the key name in Java?
推荐答案
你可以创建自己的CSV解析器,它不是很复杂但是有一些角落的情况可以成为carfull假设当然你使用的是标准的CSV格式。
You can create your own CSV parser, it's not very complicated but there are a few corner cases to be carfull with assuming of course you are using standard CSV format.
但为什么要重新发明轮子......
But why reinventing the wheel...
你可以尝试一下一个CSV解析器,如
You can try looking up a CSV parser like
- OpenCSV
- SuperCSV
- Apache Commons
还有其他人,环顾四周我相信你会找到一个适合你需要的。
There are others, look around I'm sure you will find one that suits your needs.
这篇关于从字符串java中检索值的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!