【发布时间】:2012-06-14 16:25:26
【问题描述】:
我正在使用 Qt/KDE 开发一个应用程序。在为此编写代码时,我需要读取包含 (; delimited) 等值的 QString
<http://example.com/example.ext.torrent>; rel=describedby; type="application/x-bittorrent"; name="differentname.ext"
我需要将每个属性(如 rel、类型和名称)读入不同的 QString。到目前为止我采取的方法是这样的
if (line.contains("describedby")) {
m_reltype = "describedby" ;
}
if (line.contains("duplicate")) {
m_reltype = "duplicate";
}
也就是说,如果我只需要对属性的存在(而不是它的值)感到困扰,我将手动查找文本并设置属性是否存在。但是,这种方法对于需要将实际值存储在QString 中的“类型”和名称等属性失败。虽然我知道这可以通过在分隔符; 处拆分整个字符串然后搜索属性或其值来完成,但我想知道是否有更清洁和更有效的方法来做到这一点。
【问题讨论】: