Splitting Strings by slashes

I'm just wondering how i can split a string by both front slashes (/) & backslashes (). So for example, these types of strings;

"X:/Blah/blah/"
"X:\Blah\blah\"

And also mixed slashes;

"X:/Blah\blah/"

Would work & in each case return: "X:", "Blah", "blah"

I believe i will need to use a QRegExp, http://doc.qt.io/archives/qt-4.7/qregexp.html but i'm just not sure what character set i will need to use.

Answers


str.split( QRegExp("[/\\\\]") );

The regex needs two backslashes to prevent the backslash character from escaping the ] character, and C++ adds an additional two so that you're passing in \ literals.


Need Your Help

Trying to use Rhino, getEngineByName(“JavaScript”) returns null in OpenJDK 7

java javascript rhino openjdk javax.script

When I run the following piece of code, the engine variable is set to null when I'm using OpenJDK 7 (java-7-openjdk-i386).

Getting FLV duration with php

php flv duration

I have an flv file uploaded to a server. I would like to display its duration in the following format "minutes:seconds". Can anybody help me with this ?