I have got a std::string like this:
std::string fileName;
where fileName is like /tmp/fs////js//config.js
It is coming from somewhere and I need to store it. But when I store it, I need to remove extra ‘/’ chars from the path, basically need only one separator between directory names and file names.
I can remove these by iterating over the string one char at a time and comparing with the next char, but its not very efficient.
Can anyone suggest some efficient way to do it?
You’re not going to find anything more efficient than that – think about it – you need to remove consecutive duplicated characters – the imnplication is that, even in the best case, you’re going to have to look at every character at least once.