Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#检查磁盘如何获取部分输出_C#_String_Split_Trim - Fatal编程技术网

C#检查磁盘如何获取部分输出

C#检查磁盘如何获取部分输出,c#,string,split,trim,C#,String,Split,Trim,我正在尝试为checkdisk制作一个GUI,它可以工作,但它返回一个大字符串,如下所示: 文件系统的类型是NTFS WARNING! F parameter not specified. Running CHKDSK in read-only mode. Stage 1: Examining basic file system structure ... Progress: 0 of 203264 done; Stage: 0%; Total: 0%; ETA: 0:09:48

我正在尝试为checkdisk制作一个GUI,它可以工作,但它返回一个大字符串,如下所示:

文件系统的类型是NTFS

WARNING!  F parameter not specified.
Running CHKDSK in read-only mode.

Stage 1: Examining basic file system structure ...
Progress: 0 of 203264 done; Stage:  0%; Total:  0%; ETA:   0:09:48    
Progress: 10497 of 203264 done; Stage:  5%; Total:  1%; ETA:   0:09:39 .  
Progress: 23041 of 203264 done; Stage: 11%; Total:  3%; ETA:   0:09:26 .. 
Progress: 35329 of 203264 done; Stage: 17%; Total:  5%; ETA:   0:00:22 ...
Progress: 47105 of 203264 done; Stage: 23%; Total:  7%; ETA:   0:00:22    
Progress: 58369 of 203264 done; Stage: 28%; Total:  9%; ETA:   0:00:22 .  
Progress: 69889 of 203264 done; Stage: 34%; Total: 11%; ETA:   0:00:22 .. 
Progress: 82433 of 203264 done; Stage: 40%; Total: 13%; ETA:   0:00:22 ...
Progress: 94977 of 203264 done; Stage: 46%; Total: 15%; ETA:   0:00:20    
Progress: 107265 of 203264 done; Stage: 52%; Total: 17%; ETA:   0:00:20 .  
Progress: 119553 of 203264 done; Stage: 58%; Total: 19%; ETA:   0:00:20 .. 
Progress: 131329 of 203264 done; Stage: 64%; Total: 21%; ETA:   0:00:20 ...
Progress: 143873 of 203264 done; Stage: 70%; Total: 23%; ETA:   0:00:19    
Progress: 156161 of 203264 done; Stage: 76%; Total: 25%; ETA:   0:00:19 .  
Progress: 168118 of 203264 done; Stage: 82%; Total: 27%; ETA:   0:00:19 .. 
Progress: 180481 of 203264 done; Stage: 88%; Total: 29%; ETA:   0:00:17 ...
Progress: 192769 of 203264 done; Stage: 94%; Total: 32%; ETA:   0:00:17    
Progress: 203264 of 203264 done; Stage: 100%; Total: 33%; ETA:   0:00:17 .  


  203264 file records processed.                                                        

File verification completed.
Progress: 0 of 0 done; Stage: 99%; Total: 34%; ETA:   0:00:17 .. 


  0 large file records processed.                                   

Progress: 0 of 0 done; Stage: 99%; Total: 34%; ETA:   0:00:17 ...


  0 bad file records processed.                                     


Stage 2: Examining file name linkage ...
Progress: 10520 of 225234 done; Stage:  4%; Total: 36%; ETA:   0:00:15    
Progress: 89156 of 225234 done; Stage: 39%; Total: 49%; ETA:   0:00:09 .  
Progress: 172336 of 225234 done; Stage: 76%; Total: 63%; ETA:   0:00:06 .. 
Progress: 203306 of 225234 done; Stage: 90%; Total: 68%; ETA:   0:00:04 ...
Progress: 203561 of 225234 done; Stage: 90%; Total: 68%; ETA:   0:00:04    
Progress: 203676 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:04 .  
Progress: 203718 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:04 .. 
Progress: 203741 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:04 ...
Progress: 203761 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:04    
Progress: 203775 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:04 .  
Progress: 203792 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:04 .. 
Progress: 203813 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:04 ...
Progress: 203826 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:04    
Progress: 203835 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:05 .  
Progress: 203840 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:05 .. 
Progress: 203846 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:06 ...
Progress: 203855 of 225234 done; Stage: 90%; Total: 69%; ETA:   0:00:06    
Progress: 203862 of 225234 done; Stage: 90%; Total: 70%; ETA:   0:00:06 .  
Progress: 204035 of 225234 done; Stage: 90%; Total: 70%; ETA:   0:00:06 .. 
Progress: 204123 of 225234 done; Stage: 90%; Total: 70%; ETA:   0:00:06 ...
Progress: 204142 of 225234 done; Stage: 90%; Total: 70%; ETA:   0:00:06    
Progress: 204165 of 225234 done; Stage: 90%; Total: 70%; ETA:   0:00:06 .  
Progress: 204182 of 225234 done; Stage: 90%; Total: 71%; ETA:   0:00:06 .. 
Progress: 204234 of 225234 done; Stage: 90%; Total: 71%; ETA:   0:00:06 ...
Progress: 204240 of 225234 done; Stage: 90%; Total: 72%; ETA:   0:00:06    
Progress: 204249 of 225234 done; Stage: 90%; Total: 72%; ETA:   0:00:06 .  
Progress: 204264 of 225234 done; Stage: 90%; Total: 72%; ETA:   0:00:06 .. 
Progress: 204418 of 225234 done; Stage: 90%; Total: 72%; ETA:   0:00:08 ...
Progress: 204554 of 225234 done; Stage: 90%; Total: 73%; ETA:   0:00:08    
Progress: 204710 of 225234 done; Stage: 90%; Total: 73%; ETA:   0:00:08 .  
Progress: 204771 of 225234 done; Stage: 90%; Total: 73%; ETA:   0:00:08 .. 
Progress: 204839 of 225234 done; Stage: 90%; Total: 73%; ETA:   0:00:08 ...
Progress: 204966 of 225234 done; Stage: 91%; Total: 73%; ETA:   0:00:08    
Progress: 205132 of 225234 done; Stage: 91%; Total: 73%; ETA:   0:00:08 .  
Progress: 205148 of 225234 done; Stage: 91%; Total: 74%; ETA:   0:00:08 .. 
Progress: 205167 of 225234 done; Stage: 91%; Total: 74%; ETA:   0:00:08 ...
Progress: 205179 of 225234 done; Stage: 91%; Total: 74%; ETA:   0:00:08    
Progress: 205213 of 225234 done; Stage: 91%; Total: 75%; ETA:   0:00:08 .  
Progress: 205268 of 225234 done; Stage: 91%; Total: 75%; ETA:   0:00:08 .. 
Progress: 205373 of 225234 done; Stage: 91%; Total: 75%; ETA:   0:00:08 ...
Progress: 205517 of 225234 done; Stage: 91%; Total: 75%; ETA:   0:00:08    
Progress: 205657 of 225234 done; Stage: 91%; Total: 75%; ETA:   0:00:08 .  
Progress: 205787 of 225234 done; Stage: 91%; Total: 75%; ETA:   0:00:08 .. 
Progress: 205851 of 225234 done; Stage: 91%; Total: 75%; ETA:   0:00:08 ...
Progress: 205986 of 225234 done; Stage: 91%; Total: 75%; ETA:   0:00:09    
Progress: 206065 of 225234 done; Stage: 91%; Total: 76%; ETA:   0:00:09 .  
Progress: 206861 of 225234 done; Stage: 91%; Total: 76%; ETA:   0:00:09 .. 
Progress: 207366 of 225234 done; Stage: 92%; Total: 77%; ETA:   0:00:09 ...
Progress: 207394 of 225234 done; Stage: 92%; Total: 77%; ETA:   0:00:09    
Progress: 207454 of 225234 done; Stage: 92%; Total: 77%; ETA:   0:00:09 .  
Progress: 207491 of 225234 done; Stage: 92%; Total: 78%; ETA:   0:00:09 .. 
Progress: 207553 of 225234 done; Stage: 92%; Total: 78%; ETA:   0:00:09 ...
Progress: 207591 of 225234 done; Stage: 92%; Total: 78%; ETA:   0:00:09    
Progress: 207643 of 225234 done; Stage: 92%; Total: 78%; ETA:   0:00:09 .  
Progress: 207704 of 225234 done; Stage: 92%; Total: 78%; ETA:   0:00:09 .. 
Progress: 207737 of 225234 done; Stage: 92%; Total: 78%; ETA:   0:00:09 ...
Progress: 207767 of 225234 done; Stage: 92%; Total: 79%; ETA:   0:00:09    
Progress: 207827 of 225234 done; Stage: 92%; Total: 79%; ETA:   0:00:09 .  
Progress: 207900 of 225234 done; Stage: 92%; Total: 79%; ETA:   0:00:09 .. 
Progress: 207950 of 225234 done; Stage: 92%; Total: 79%; ETA:   0:00:09 ...
Progress: 208007 of 225234 done; Stage: 92%; Total: 80%; ETA:   0:00:09    
Progress: 208080 of 225234 done; Stage: 92%; Total: 80%; ETA:   0:00:09 .  
Progress: 208130 of 225234 done; Stage: 92%; Total: 80%; ETA:   0:00:09 .. 
Progress: 208179 of 225234 done; Stage: 92%; Total: 80%; ETA:   0:00:09 ...
Progress: 208184 of 225234 done; Stage: 92%; Total: 81%; ETA:   0:00:09    
Progress: 208334 of 225234 done; Stage: 92%; Total: 81%; ETA:   0:00:09 .  
Progress: 208605 of 225234 done; Stage: 92%; Total: 81%; ETA:   0:00:09 .. 
Progress: 208720 of 225234 done; Stage: 92%; Total: 81%; ETA:   0:00:09 ...
Progress: 208872 of 225234 done; Stage: 92%; Total: 81%; ETA:   0:00:09    
Progress: 208919 of 225234 done; Stage: 92%; Total: 81%; ETA:   0:00:09 .  
Progress: 209266 of 225234 done; Stage: 92%; Total: 81%; ETA:   0:00:09 .. 
Progress: 209402 of 225234 done; Stage: 92%; Total: 81%; ETA:   0:00:09 ...
Progress: 209553 of 225234 done; Stage: 93%; Total: 82%; ETA:   0:00:09    
Progress: 209600 of 225234 done; Stage: 93%; Total: 82%; ETA:   0:00:09 .  
Progress: 209627 of 225234 done; Stage: 93%; Total: 82%; ETA:   0:00:09 .. 
Progress: 209638 of 225234 done; Stage: 93%; Total: 82%; ETA:   0:00:09 ...
Progress: 209643 of 225234 done; Stage: 93%; Total: 82%; ETA:   0:00:09    
Progress: 209681 of 225234 done; Stage: 93%; Total: 82%; ETA:   0:00:09 .  
Progress: 209689 of 225234 done; Stage: 93%; Total: 82%; ETA:   0:00:09 .. 
Progress: 209797 of 225234 done; Stage: 93%; Total: 83%; ETA:   0:00:09 ...
Progress: 209823 of 225234 done; Stage: 93%; Total: 83%; ETA:   0:00:09    
Progress: 209829 of 225234 done; Stage: 93%; Total: 83%; ETA:   0:00:09 .  
Progress: 209837 of 225234 done; Stage: 93%; Total: 84%; ETA:   0:00:09 .. 
Progress: 209851 of 225234 done; Stage: 93%; Total: 84%; ETA:   0:00:09 ...
Progress: 209941 of 225234 done; Stage: 93%; Total: 84%; ETA:   0:00:09    
Progress: 210086 of 225234 done; Stage: 93%; Total: 84%; ETA:   0:00:09 .  
Progress: 210110 of 225234 done; Stage: 93%; Total: 85%; ETA:   0:00:09 .. 
Progress: 210419 of 225234 done; Stage: 93%; Total: 85%; ETA:   0:00:09 ...
Progress: 210467 of 225234 done; Stage: 93%; Total: 85%; ETA:   0:00:09    
Progress: 210507 of 225234 done; Stage: 93%; Total: 85%; ETA:   0:00:09 .  
Progress: 210568 of 225234 done; Stage: 93%; Total: 85%; ETA:   0:00:09 .. 
Progress: 210615 of 225234 done; Stage: 93%; Total: 85%; ETA:   0:00:09 ...
Progress: 210643 of 225234 done; Stage: 93%; Total: 86%; ETA:   0:00:09    
Progress: 210771 of 225234 done; Stage: 93%; Total: 86%; ETA:   0:00:09 .  
Progress: 210825 of 225234 done; Stage: 93%; Total: 86%; ETA:   0:00:09 .. 
Progress: 210845 of 225234 done; Stage: 93%; Total: 86%; ETA:   0:00:09 ...
Progress: 210850 of 225234 done; Stage: 93%; Total: 86%; ETA:   0:00:09    
Progress: 210873 of 225234 done; Stage: 93%; Total: 86%; ETA:   0:00:09 .  
Progress: 210914 of 225234 done; Stage: 93%; Total: 86%; ETA:   0:00:09 .. 
Progress: 210993 of 225234 done; Stage: 93%; Total: 87%; ETA:   0:00:09 ...
Progress: 211060 of 225234 done; Stage: 93%; Total: 87%; ETA:   0:00:09    
Progress: 211105 of 225234 done; Stage: 93%; Total: 87%; ETA:   0:00:09 .  
Progress: 211137 of 225234 done; Stage: 93%; Total: 87%; ETA:   0:00:09 .. 
Progress: 211195 of 225234 done; Stage: 93%; Total: 87%; ETA:   0:00:09 ...
Progress: 211836 of 225234 done; Stage: 94%; Total: 87%; ETA:   0:00:09    
Progress: 212165 of 225234 done; Stage: 94%; Total: 87%; ETA:   0:00:09 .  
Progress: 212240 of 225234 done; Stage: 94%; Total: 88%; ETA:   0:00:09 .. 
Progress: 212641 of 225234 done; Stage: 94%; Total: 88%; ETA:   0:00:09 ...
Progress: 212720 of 225234 done; Stage: 94%; Total: 88%; ETA:   0:00:09    
Progress: 212743 of 225234 done; Stage: 94%; Total: 88%; ETA:   0:00:09 .  
Progress: 212749 of 225234 done; Stage: 94%; Total: 89%; ETA:   0:00:08 .. 
Progress: 212781 of 225234 done; Stage: 94%; Total: 89%; ETA:   0:00:07 ...
Progress: 213293 of 225234 done; Stage: 94%; Total: 89%; ETA:   0:00:07    
Progress: 213430 of 225234 done; Stage: 94%; Total: 90%; ETA:   0:00:07 .  
Progress: 213578 of 225234 done; Stage: 94%; Total: 90%; ETA:   0:00:07 .. 
Progress: 213624 of 225234 done; Stage: 94%; Total: 90%; ETA:   0:00:07 ...
Progress: 213693 of 225234 done; Stage: 94%; Total: 90%; ETA:   0:00:07    
Progress: 213730 of 225234 done; Stage: 94%; Total: 90%; ETA:   0:00:07 .  
Progress: 213809 of 225234 done; Stage: 94%; Total: 90%; ETA:   0:00:07 .. 
Progress: 213819 of 225234 done; Stage: 94%; Total: 90%; ETA:   0:00:07 ...
Progress: 213891 of 225234 done; Stage: 94%; Total: 90%; ETA:   0:00:07    
Progress: 214128 of 225234 done; Stage: 95%; Total: 91%; ETA:   0:00:07 .  
Progress: 225234 of 225234 done; Stage: 100%; Total: 91%; ETA:   0:00:06 .. 


  225234 index entries processed.                                                       

Index verification completed.
Progress: 0 of 0 done; Stage: 99%; Total: 91%; ETA:   0:00:06 ...


  0 unindexed files scanned.                                        

Progress: 0 of 0 done; Stage: 99%; Total: 91%; ETA:   0:00:06    


  0 unindexed files recovered.                                      


Stage 3: Examining security descriptors ...
Security descriptor verification completed.
Progress: 1 of 1 done; Stage: 100%; Total: 99%; ETA:   0:00:00 .  


  10986 data files processed.                                           

CHKDSK is verifying Usn Journal...
Progress: 0 of 1228 done; Stage:  0%; Total: 99%; ETA:   0:00:00 .. 
Progress: 131 of 1228 done; Stage: 10%; Total: 99%; ETA:   0:00:00 ...
Progress: 1049 of 1228 done; Stage: 85%; Total: 99%; ETA:   0:00:00    
Progress: 1228 of 1228 done; Stage: 100%; Total: 99%; ETA:   0:00:00 .  

                                                                                       10064304 USN bytes processed.                                                           

Usn Journal verification completed.

Windows has scanned the file system and found no problems.
No further action is required.

 976756735 KB total disk space.
 262122464 KB in 192140 files.
     51752 KB in 10987 indexes.
         0 KB in bad sectors.
    309295 KB in use by the system.
     65536 KB occupied by the log file.
 714273224 KB available on disk.

      4096 bytes in each allocation unit.
 244189183 total allocation units on disk.
 178568306 allocation units available on disk.
现在,我只希望此字符串的文本来自: Usn日志验证已完成

直到绳子的尽头


如果您已经有一个
字符串[]

,我该怎么做呢

var relevantLines = allLines
  .SkipWhile(l => !l.StartsWith("Usn Journal verification completed", StringComparison.CurrentCultureIgnoreCase));  // omit the second parameter if you want to compare case sensitive
否则使用
字符串。拆分

string[] allLines = allText
  .Split(new[]{ Environment.NewLine }, StringSplitOptions.None);
如果希望字符串作为最终结果,请使用
string.Join

string result = string.Join(Environment.NewLine, relevantLines);

最简单的方法可能只是找到字符串“Usn Journal Verification completed”(Usn日志验证已完成)并从中获取一个子字符串:

string s = ???; // your string
int pos = s.IndexOf("Usn Journal Verification completed");
string outString = s.Substring(pos);

您需要执行一些错误检查以确保找到字符串等。

我们可能不需要整个字符串。。。为了将来参考,HH所以基本上我需要将我的字符串转换为字符串[],然后搜索包含正确文本的字符串[],然后从所有下一个字符串[]项中获取文本。@Nobleleader13245:是的,如果是文件,可以使用
file.ReadLines
file.ReadAllLines
。如果需要搜索结果,可以使用
string.Join
(编辑my naswer)。