gpt4 book ai didi

c++ - 将 QStringList 打包成 QString 并解压回来

转载 作者:可可西里 更新时间:2023-11-01 16:26:00 28 4
gpt4 key购买 nike

我正在寻找一种简单且万无一失的方法来将任意 QStringList 转换为单个 QString 并返回。

QStringList fruits;
fruits << "Banana", "Apple", "Orange";
QString packedFruits = pack(fruits);
QStringList unpackFruits = unpack(packedFruits);

// Should be true
// fruits == unpackFruits;

对于此类问题,最简单的解决方案可能是什么?

最佳答案

QStringListQString - QStringList::join :

Joins all the string list's strings into a single string with each element separated by the given separator (which can be an empty string).

QString pack(QStringList const& list)
{
return list.join(reserved_separator);
}

QStringQStringList - QString::split :

Splits the string into substrings wherever sep occurs, and returns the list of those strings. If sep does not match anywhere in the string, split() returns a single-element list containing this string.

QStringList unpack(QString const& string)
{
return string.split(reserved_separator);
}

关于c++ - 将 QStringList 打包成 QString 并解压回来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37538981/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com