www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - "if sting in string"

reply smadus <kurz.andi gmx.ch> writes:
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
Sep 16 2015
next sibling parent cym13 <cpicard openmailbox.org> writes:
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?
Sep 16 2015
prev sibling next sibling parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
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.
Sep 16 2015
parent smadus <kurz.andi gmx.ch> writes:
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...
Sep 16 2015
prev sibling parent reply John Colvin <john.loughran.colvin gmail.com> writes:
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
Sep 16 2015
parent reply smadus <kurz.andi gmx.ch> writes:
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.
Sep 18 2015
next sibling parent yawniek <dlang srtnwz.com> writes:
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
Sep 18 2015
prev sibling parent reply John Colvin <john.loughran.colvin gmail.com> writes:
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.
Sep 18 2015
parent reply John Colvin <john.loughran.colvin gmail.com> writes:
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
Sep 18 2015
parent John Colvin <john.loughran.colvin gmail.com> writes:
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
Sep 18 2015