資源簡介
C#操作TXT的實力,包括新建,刪除,以及字符串處理

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.IO;
namespace?WindowsFormsApplication6
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????textBox1.Text?=“C:\\Users\\jack\\Desktop\\cass4.0數據格式\\“;
????????????textBox2.Text?=“G:\\txt處理后\\“;
????????????
????????????string?SourcePath=textBox1.Text;
????????????string?DestinationPath?=?textBox2.Text;
????????????DirectoryInfo?Directory?=?new?DirectoryInfo(SourcePath);
????????????foreach?(FileInfo?file?in?Directory.GetFiles())
????????????{???
?????????????
????????????StreamReader?sr?=?new?StreamReader(SourcePath?+?file.Name);
????????????string[]?lines?=?File.ReadAllLines(SourcePath?+?file.Name);
????????????int?a?=?0;
????????????string?Combina=““;
????????????List?needs?=?new?List();
????????????foreach(string?line?in?lines)
????????????{
???????????????//?a=a+1;
???????????????//?string?Combina=““;
????????????????if?(line.Length?>4)
????????????????{
????????????????????needs.Add(line);?
????????????????}?????
???????????????????
????????????}
????????????needs.RemoveAt(0);
????????????int?count?=?0;
????????????List?Combination?=?new?List();
????????????for?(int?y?=?2;?y?<=?needs.Count;?y=y+2)
????????????{
????????????????Combina?=“355“+needs[y-1]?+““?+“35“?+?needs[y];????//合并
????????????????count?=?count?+?1;??????????//用來統計合并了多少個數據
????????????????Combination.Add(Combina);???????//用另一個數組存儲合并后數據
????????????}
????????????for?(int?z?=?1;?z?<=?count*2;?z++)
????????????{
????????????????needs.RemoveAt(1);
????????????}
????????????for?(int?i?=?0;?i?????????????{
????????????????needs.Add(Combination[i]);
????????????}
????????????
????????????WriteInTxt(DestinationPath?+?file.Name?needs);
?????????????
????????????????}
????????}
????????public?static?void?WriteInTxt(string?DestinationPathList?needs)
????????{
????????????string?WriteInPath?=?DestinationPath;
????????????int?NumberCount?=needs.Count;
????????????int?i=0;
????????????if?(!File.Exists(WriteInPath))
????????????{
????????????????FileStream?fs1?=?new?FileStream(WriteInPath?FileMode.Create?FileAccess.Write);//創建寫入文件????????
????????????????StreamWriter?sw?=?new?StreamWriter(fs1);
????????????????for(i?=?0;i?????????????????{
????????????????????sw.WriteLine(needs[i]);//開始寫入值??
????????????????}
????????????????????
????????????????sw.Close();
????????????????fs1.Close();
????????????}
????????????else
????????????{
????????????????FileStream?fs?=?new?FileStream(WriteInPath?FileMode.Open?FileAccess.Write);
????????????????Str
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????9728??2014-10-24?09:47??txt讀寫\WindowsFormsApplication6\bin\Debug\WindowsFormsApplication6.exe
?????文件??????30208??2014-10-24?09:47??txt讀寫\WindowsFormsApplication6\bin\Debug\WindowsFormsApplication6.pdb
?????文件??????24224??2014-11-17?11:11??txt讀寫\WindowsFormsApplication6\bin\Debug\WindowsFormsApplication6.vshost.exe
?????文件????????490??2013-06-18?20:28??txt讀寫\WindowsFormsApplication6\bin\Debug\WindowsFormsApplication6.vshost.exe.manifest
?????文件???????3384??2014-10-24?09:47??txt讀寫\WindowsFormsApplication6\Form1.cs
?????文件???????2983??2014-10-22?16:14??txt讀寫\WindowsFormsApplication6\Form1.Designer.cs
?????文件???????5817??2014-10-22?16:14??txt讀寫\WindowsFormsApplication6\Form1.resx
?????文件???????5420??2014-10-22?16:35??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7168??2014-11-17?11:11??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????1258??2014-10-22?19:05??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\WindowsFormsApplication6.csproj.FileListAbsolute.txt
?????文件????????975??2014-10-22?16:14??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\WindowsFormsApplication6.csproj.GenerateResource.Cache
?????文件???????9174??2014-10-22?17:02??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\WindowsFormsApplication6.csprojResolveAssemblyReference.cache
?????文件???????9728??2014-10-24?09:47??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\WindowsFormsApplication6.exe
?????文件????????180??2014-10-22?16:14??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\WindowsFormsApplication6.Form1.resources
?????文件??????30208??2014-10-24?09:47??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\WindowsFormsApplication6.pdb
?????文件????????180??2014-10-22?16:14??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\WindowsFormsApplication6.Properties.Resources.resources
?????文件???????1508??2014-11-17?11:11??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\數據格式轉化.csproj.FileListAbsolute.txt
?????文件????????975??2014-10-24?09:47??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\數據格式轉化.csproj.GenerateResource.Cache
?????文件???????9214??2014-10-24?09:47??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\數據格式轉化.csprojResolveAssemblyReference.cache
?????文件????????505??2014-10-22?15:49??txt讀寫\WindowsFormsApplication6\Program.cs
?????文件???????1380??2014-10-22?15:49??txt讀寫\WindowsFormsApplication6\Properties\AssemblyInfo.cs
?????文件???????2900??2014-10-22?15:49??txt讀寫\WindowsFormsApplication6\Properties\Resources.Designer.cs
?????文件???????5612??2014-10-22?15:49??txt讀寫\WindowsFormsApplication6\Properties\Resources.resx
?????文件???????1111??2014-10-22?15:49??txt讀寫\WindowsFormsApplication6\Properties\Settings.Designer.cs
?????文件????????249??2014-10-22?15:49??txt讀寫\WindowsFormsApplication6\Properties\Settings.settings
?????文件???????3707??2014-10-22?16:14??txt讀寫\WindowsFormsApplication6\數據格式轉化.csproj
?????文件????????902??2014-10-22?19:07??txt讀寫\數據格式轉化.sln
????..A..H.?????31232??2014-11-07?10:15??txt讀寫\數據格式轉化.suo
????..A..H.?????53248??2014-11-17?11:59??txt讀寫\數據格式轉化.v12.suo
?????目錄??????????0??2014-10-22?15:49??txt讀寫\WindowsFormsApplication6\obj\x86\Debug\TempPE
............此處省略11個文件信息
- 上一篇:c#倉庫信息管理系統
- 下一篇:Aspose.Pdf生成pdf
評論
共有 條評論