Search code examples
c#readlinessystem.io.file

C# How to select any character if line starts with " *:"


I've read a Textfile using the readline method.

var txtfile = File.readlines([Filepath])
.where(s => s.startswith(" U:"));

Is there a trick to choose any letter? Something like this Pseudocode

s.startswith(" *:");

That's because my drive name changes continuously. Please note that it must be the exact order of letters. Thanks!


Solution

  • You can use below regular expression.

    .Where(s => Regex.Match(s,@"^\s.{1}:.*").Success);
    

    Here is a short explanation for that regex.

    ^ - start of the line

    \s - blankspace

    .{1} - exactly one occurrence of any character

    : - match semicolon

    .* - 0 or more characters