Small iterators/algorithm usage feedback

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Apr 26 19:28:36 PDT 2009


Denis Koroskin wrote:
> I have just started using iterators and algorithms a little.
> Given a full file path, a needed to get folder name where it is located, 
> and a name of the that file.
> 
> Using C and its standard library, I can do it as follows:
> 
> auto pos = strrpos(fullFilePath, '/'); // strrpos = strpos-reverse
> string dirName = fullFilePath[0..pos];
> string fileName = fullFilePath[pos+1..$];

I think you are confusing iterators with ranges. Iterators are gone from
Phobos.

(fixed code)

auto pos = find(retro(fullFilePath)).length - 1;
auto dirname = fullFilePath[0..pos];
auto filename = fullFilePath[pos+1..$];


Andrei



More information about the Digitalmars-d mailing list