String Manipulation
-
Hi all, I have the following string:
drwxr-xr-x 1 ftp ftp 0 Nov 09 07:04 Windows
drwxr-xr-x 1 ftp ftp 0 Oct 29 2007 Nvidia
drwxr-xr-x 1 ftp ftp 0 Jan 01 2003 Program FilesI would like to extract only the folder name i.e. "Windows" or "Program Files", but my string manipulation isn't so good in C# can anyone please help me? Many Thanks Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Hi all, I have the following string:
drwxr-xr-x 1 ftp ftp 0 Nov 09 07:04 Windows
drwxr-xr-x 1 ftp ftp 0 Oct 29 2007 Nvidia
drwxr-xr-x 1 ftp ftp 0 Jan 01 2003 Program FilesI would like to extract only the folder name i.e. "Windows" or "Program Files", but my string manipulation isn't so good in C# can anyone please help me? Many Thanks Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
The string looks broken, doesn't all the entries have both a year and a time? If they do, the number of characters before the folder name should be constant, and you can just split the string on Environment.NewLine and use .Substring(41) to get each folder name.
Experience is the sum of all the mistakes you have done.
-
The string looks broken, doesn't all the entries have both a year and a time? If they do, the number of characters before the folder name should be constant, and you can just split the string on Environment.NewLine and use .Substring(41) to get each folder name.
Experience is the sum of all the mistakes you have done.
Hi Guffa, Thanks for the response. I don't think the string is broken, as I stated in my previous post, that's how the FTP server (FileZilla) returns the directory list, but I'm on the verge of figuring it out :) Thanks Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Hi Guffa, Thanks for the response. I don't think the string is broken, as I stated in my previous post, that's how the FTP server (FileZilla) returns the directory list, but I'm on the verge of figuring it out :) Thanks Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Ok, is that the only variations there are, or are the items that are listed with both year and time, and items that are listed without both?
Experience is the sum of all the mistakes you have done.
Guffa wrote:
is that the only variations there are, or are the items that are listed with both year and time, and items that are listed without both?
Yes that is the only variants there are.
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Ok, is that the only variations there are, or are the items that are listed with both year and time, and items that are listed without both?
Experience is the sum of all the mistakes you have done.
-
Guffa, this is the way the most ?nixe show their directory entries. For older entries they show date without time, for younger date without year, but with time. But in all cases you can't rely on fixed width column structure. Regards
mabo42 wrote:
But in all cases you can't rely on fixed width column structure.
So what can one rely on ...
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
mabo42 wrote:
But in all cases you can't rely on fixed width column structure.
So what can one rely on ...
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
mabo42 wrote:
But in all cases you can't rely on fixed width column structure.
So what can one rely on ...
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
To make it more clear, this is a sample listing:
drwxr-x--- 2 ftp ftp 8192 Nov 19 12:14 .
drwxr-xr-x 11 ftp ftp 8192 Nov 19 12:35 ..
-rw-r----- 1 someone someone 8639750144 Nov 19 12:14 this_is_a_long_file_name.dat
-rw-r----- 1 ftp ftp 6260006912 Nov 19 13:13 shortname.datThe filename (or directory name) is the 9. group (delimited by whitespace) until line end. Regards
-
mabo42 wrote:
But in all cases you can't rely on fixed width column structure.
So what can one rely on ...
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
You could try this function, should work:
using System.Text.RegularExpressions;
public string EntryName(string line)
{
Regex regex = new Regex(@"[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+(?<ENTRY>.*)");
Match match = regex.Match(line);
return match.Groups["ENTRY"].Value.Trim();
}Regards
-
To make it more clear, this is a sample listing:
drwxr-x--- 2 ftp ftp 8192 Nov 19 12:14 .
drwxr-xr-x 11 ftp ftp 8192 Nov 19 12:35 ..
-rw-r----- 1 someone someone 8639750144 Nov 19 12:14 this_is_a_long_file_name.dat
-rw-r----- 1 ftp ftp 6260006912 Nov 19 13:13 shortname.datThe filename (or directory name) is the 9. group (delimited by whitespace) until line end. Regards
Thank you mabo42 :) Regards
The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^
-
Guffa, this is the way the most ?nixe show their directory entries. For older entries they show date without time, for younger date without year, but with time. But in all cases you can't rely on fixed width column structure. Regards
Yeah, one of the worst things about Unix.