tags:

views:

42

answers:

2

How can i check if filename contains some string? for example if "frody" contains "ro"? I tried like that:

                    if (file_name.Contains("ro")== true)

and:

                       if (file_name.Contains("ro"))
+3  A: 

Both are correct. The second is probably more favoured.

E.g., this returns true:

string s = "test-ro.doc";
Console.WriteLine(s.Contains("ro"));
RedFilter
Watch out for a NullPointerException on file_name though.
Jeremy Goodell
I would also suggest to ignore case.
Nix
A: 
if (s == null || s.Trim().Length == 0) 
{ 
   return false 
} 
else 
{ 
   return s.ToLower().Contains("ro");
}
sh_kamalh
Thanks. I have another problem. Thanks for help.