split() is a member function in the QString class that splits a string into substrings and stores the results in a list of strings

split() is a member function in the QString class that splits a string into substrings and stores the results in a list of strings.

The following are common uses of the split() function:

QString str = "Hello, World!";
QStringList stringList = str.split(", ");  // 返回 ["Hello", "World!"]

In this example, we have a string str that reads "Hello, World!". By calling the split() function and passing an argument as the separator, you can split a string into multiple substrings and store the result in a QStringList object.

In the split() function, we pass a parameter as the delimiter, here we use ", " as the delimiter. Call split(", ") to split the string str using commas and spaces as delimiters to generate a QStringList containing two substrings, That is ["Hello", "World!"].

It should be noted that the split() function returns a list of strings containing split substrings. The original string is not modified.

Guess you like

Origin blog.csdn.net/m0_46376834/article/details/134910753