Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any Qt container that returns its values as comma separated string?

Tags:

csv

qt

containers

In Qt, does one of the containers give me the option to return a comma-separated string from its values?

like image 466
user63898 Avatar asked Apr 30 '11 13:04

user63898


People also ask

How do you store a comma-separated string in an array?

Answer: Use the split() Method You can use the JavaScript split() method to split a string using a specific separator such as comma ( , ), space, etc. If separator is an empty string, the string is converted to an array of characters.

What is a QStringList?

The QStringList class provides a list of strings. QStringList inherits from QList<QString>. Like QList, QStringList is implicitly shared. It provides fast index-based access as well as fast insertions and removals. Passing string lists as value parameters is both fast and safe.

How do you declare a QStringList?

QStringList::QStringList(const QString &str) Constructs a string list that contains the given string, str. Longer lists are easily created like this: QStringList longerList = (QStringList() << str1 << str2 << str3); See also append().


1 Answers

If your elements are QStrings, you can use QStringList::join():

QStringList list;
list << "one" << "two" << "three";
QString s = list.join(",");
// s == "one,two,three"
like image 150
Marc Mutz - mmutz Avatar answered Nov 10 '22 06:11

Marc Mutz - mmutz