Which option is faster...
John Colvin
john.loughran.colvin at gmail.com
Mon Aug 5 08:52:14 PDT 2013
On Monday, 5 August 2013 at 15:21:25 UTC, David wrote:
> Am 05.08.2013 15:59, schrieb jicman:
>>
>> Greetings!
>>
>> I have this code,
>>
>> foreach (...)
>> {
>>
>> if (std.string.tolower(fext[0]) == "doc" ||
>> std.string.tolower(fext[0]) == "docx" ||
>> std.string.tolower(fext[0]) == "xls" ||
>> std.string.tolower(fext[0]) == "xlsx" ||
>> std.string.tolower(fext[0]) == "ppt" ||
>> std.string.tolower(fext[0]) == "pptx")
>> continue;
>> }
>>
>
> That's how I would do it.
>
> if(["doc", "docx", "xls", "xlsx", "ppt",
> "pptx"].canFind(fext[0].toLower) {
> continue;
> }
>
> With the array beeing a runtime/compiletime constant with a
> sensible
> name. WORD_EXTENSIONS or something.
In case some of the strings are actually rather long, one could
use toLower lazily (either std.ascii.toLower or std.uni.toLower,
depending on which you need):
if(WORD_EXT.canFind(fext[0].map!toLower()))
More information about the Digitalmars-d-learn
mailing list