Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用以下格式格式化 QString:
QString("%1000%2").arg("ABC", "DEF");
我预计输出是,"ABC000DEF"但实际上是"%1000ABC"。
"ABC000DEF"
"%1000ABC"
我怎样才能克服歧义?
它没有看到“%1”“000”“%2”,它看到了“%10”“00”“%2”(地标范围从 1 到 99)
解决方法可能是
QString("%1%2%3").arg("ABC", "000", "DEF");
另一种解决方法是使用replace而不是arg,它不会更改原始格式字符串,但需要更多输入:
replace
arg
QString("%1000%2").replace("%1", "ABC").replace("%2", "DEF");