Thread overview
"if sting in string"
Sep 16, 2015
smadus
Sep 16, 2015
cym13
Sep 16, 2015
Rikki Cattermole
Sep 16, 2015
smadus
Sep 16, 2015
John Colvin
Sep 18, 2015
smadus
Sep 18, 2015
yawniek
Sep 18, 2015
John Colvin
Sep 18, 2015
John Colvin
Sep 18, 2015
John Colvin
September 16, 2015
Hello

Searching after hours, i give up and here is the question. ;)

I will make a programm, this searching all txt files on the system or the path from user and searching a user tiped term in this file.

http://dpaste.dzfl.pl/dec09a0f849c

The Problem is in the if() "line 17" i searching in std.algorithm, but i dont find a solution for my problem.

i hope, someone can help me.

I'm new on D and sorry for my bad english.

Happy Greetings

Shorty


September 16, 2015
On Wednesday, 16 September 2015 at 12:55:13 UTC, smadus wrote:
> Hello
>
> Searching after hours, i give up and here is the question. ;)
>
> I will make a programm, this searching all txt files on the system or the path from user and searching a user tiped term in this file.
>
> http://dpaste.dzfl.pl/dec09a0f849c
>
> The Problem is in the if() "line 17" i searching in std.algorithm, but i dont find a solution for my problem.
>
> i hope, someone can help me.
>
> I'm new on D and sorry for my bad english.
>
> Happy Greetings
>
> Shorty

Turn it into either:

    if (canFind(line, term)) {...

or

    if (line.canFind(term)) {...

(they are equivalent)

This mistake seems odd, is D your first programming language?
September 16, 2015
On 17/09/15 12:55 AM, smadus wrote:
> Hello
>
> Searching after hours, i give up and here is the question. ;)
>
> I will make a programm, this searching all txt files on the system or
> the path from user and searching a user tiped term in this file.
>
> http://dpaste.dzfl.pl/dec09a0f849c
>
> The Problem is in the if() "line 17" i searching in std.algorithm, but i
> dont find a solution for my problem.
>
> i hope, someone can help me.
>
> I'm new on D and sorry for my bad english.
>
> Happy Greetings
>
> Shorty

Highly inefficient design in code, but lets ignore that.

You want std.string : indexOf.

if (line.indexOf(term) >= 0) {

If I remember correctly.

September 16, 2015
A lot of thanks... i choose the (line.canFind(term)).

No is not my first language, Python was my first, but i dont coding a long time...

September 16, 2015
On Wednesday, 16 September 2015 at 12:55:13 UTC, smadus wrote:
> Hello
>
> Searching after hours, i give up and here is the question. ;)
>
> I will make a programm, this searching all txt files on the system or the path from user and searching a user tiped term in this file.
>
> http://dpaste.dzfl.pl/dec09a0f849c
>
> The Problem is in the if() "line 17" i searching in std.algorithm, but i dont find a solution for my problem.
>
> i hope, someone can help me.
>
> I'm new on D and sorry for my bad english.
>
> Happy Greetings
>
> Shorty

line 17 should probably be:

            if(canFind(line, term)){

you had your first closing bracket in the wrong place. Also, canFind looks for the second argument inside the first argument.

Other notes:

There is no need to pass the arguments by ref, the data is not copied.

File has a member function called byLine that can be used like this:
foreach(line; actually_file.byLine())
    //do something with the line
see http://dlang.org/phobos/std_stdio.html#.File.byLine

No need to chomp a line before using canFind on it.

What are you trying to write on line 18? datei isn't defined anywhere
September 18, 2015
Ok i have rewrite :)

Now:
http://dpaste.dzfl.pl/cf8bb54b1390

The Problem is:

http://www.directupload.net/file/d/4114/9zryku49_png.htm

but i dont understand this, because, the exception should be "Something wrong" ?!?

But, thanks for the answers, realy good and the code has been smaller.
September 18, 2015
On Friday, 18 September 2015 at 09:42:05 UTC, smadus wrote:
> Ok i have rewrite :)
>
> Now:
> http://dpaste.dzfl.pl/cf8bb54b1390
>
> The Problem is:
>
> http://www.directupload.net/file/d/4114/9zryku49_png.htm
>
> but i dont understand this, because, the exception should be "Something wrong" ?!?
>
> But, thanks for the answers, realy good and the code has been smaller.

the question is if there is a way to handle inaccessible directories with
dirEntries.
the problem is that if you have a directory with insufficent access rights it throws a FileException
September 18, 2015
On Friday, 18 September 2015 at 09:42:05 UTC, smadus wrote:
> Ok i have rewrite :)
>
> Now:
> http://dpaste.dzfl.pl/cf8bb54b1390
>
> The Problem is:
>
> http://www.directupload.net/file/d/4114/9zryku49_png.htm
>
> but i dont understand this, because, the exception should be "Something wrong" ?!?
>
> But, thanks for the answers, realy good and the code has been smaller.

There are two other points where an Exception could be thrown: during the construction of dirEntries and on every iteration of it.

See http://dpaste.dzfl.pl/d38307643f9b for a corrected version. It's not pretty

I think this has shown up a design flaw in dirEntries, this should be much easier.
September 18, 2015
On Friday, 18 September 2015 at 11:18:33 UTC, John Colvin wrote:
> On Friday, 18 September 2015 at 09:42:05 UTC, smadus wrote:
>> Ok i have rewrite :)
>>
>> Now:
>> http://dpaste.dzfl.pl/cf8bb54b1390
>>
>> The Problem is:
>>
>> http://www.directupload.net/file/d/4114/9zryku49_png.htm
>>
>> but i dont understand this, because, the exception should be "Something wrong" ?!?
>>
>> But, thanks for the answers, realy good and the code has been smaller.
>
> There are two other points where an Exception could be thrown: during the construction of dirEntries and on every iteration of it.
>
> See http://dpaste.dzfl.pl/d38307643f9b for a corrected version. It's not pretty
>
> I think this has shown up a design flaw in dirEntries, this should be much easier.

Sorry, correction: http://dpaste.dzfl.pl/75945e0d839a
September 18, 2015
On Friday, 18 September 2015 at 11:26:46 UTC, John Colvin wrote:
> On Friday, 18 September 2015 at 11:18:33 UTC, John Colvin wrote:
>> On Friday, 18 September 2015 at 09:42:05 UTC, smadus wrote:
>>> Ok i have rewrite :)
>>>
>>> Now:
>>> http://dpaste.dzfl.pl/cf8bb54b1390
>>>
>>> The Problem is:
>>>
>>> http://www.directupload.net/file/d/4114/9zryku49_png.htm
>>>
>>> but i dont understand this, because, the exception should be "Something wrong" ?!?
>>>
>>> But, thanks for the answers, realy good and the code has been smaller.
>>
>> There are two other points where an Exception could be thrown: during the construction of dirEntries and on every iteration of it.
>>
>> See http://dpaste.dzfl.pl/d38307643f9b for a corrected version. It's not pretty
>>
>> I think this has shown up a design flaw in dirEntries, this should be much easier.
>
> Sorry, correction: http://dpaste.dzfl.pl/75945e0d839a

This was so embarrassingly ugly to do that I posted in the main group to see if people have better ideas: http://forum.dlang.org/post/pdwndsdfjbogtbjcnkpc@forum.dlang.org