Я хочу написать несколько файлов с этой функцией
У меня есть досье ..
И я хочу разделить этот файл с "z".
я написал код, но я хочу оптимизировать код ..
я пишу один и тот же код несколько раз ..
ранее файл состоял из 6 расколов, но теперь он состоит из 60 расколов ..
пожалуйста, помогите мне .....
Что я уже пробовал:
Dim s As String = IO.File.ReadAllText("C:\Users\mks\Desktop\Newfolder\P6.A3") Dim wFile, wFile1 As System.IO.FileStream Dim byteData(), byteData1(), byteDatayp(), byteDatayn(), byteDatabp(), byteDatabn(), byteDatarp1(), byteDatarn1(), byteDatayp1(), byteDatayn1(), byteDatabp1(), byteDatabn1() As Byte Dim rn, rp, yp, yn, bp, bn As String Dim r As String = Regex.Replace(s.ToString, "[^1-9Z-]", "") ' Console.WriteLine(r) r = Regex.Replace(r.ToString, "[-]", "0") Dim elements() As String = Regex.Split(r, "Z") For Each element In elements Next rp = elements(0) rn = elements(1) yp = elements(2) yn = elements(3) bp = elements(4) bn = elements(5) byteData = Encoding.ASCII.GetBytes(rp) byteData1 = Encoding.ASCII.GetBytes(rn) byteDatayp = Encoding.ASCII.GetBytes(yp) byteDatayn = Encoding.ASCII.GetBytes(yn) byteDatabp = Encoding.ASCII.GetBytes(yp) byteDatabn = Encoding.ASCII.GetBytes(yn) System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\ro.mod", "") wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\ro.mod", FileMode.Append) wFile.Write(byteData, 0, byteData.Length) wFile.Close() System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\rs.mod", "") wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\rs.mod", FileMode.Append) wFile1.Write(byteData1, 0, byteData1.Length) wFile1.Close() System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\yo.mod", "") wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\yo.mod", FileMode.Append) wFile.Write(byteDatayp, 0, byteDatayp.Length) wFile.Close() System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\ys.mod", "") wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\ys.mod", FileMode.Append) wFile1.Write(byteDatayn, 0, byteDatayn.Length) wFile1.Close() System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\bo.mod", "") wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\bo.mod", FileMode.Append) wFile.Write(byteDatabp, 0, byteDatabp.Length) wFile.Close() System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\bs.mod", "") wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\bs.mod", FileMode.Append) wFile1.Write(byteDatabn, 0, byteDatabn.Length) wFile1.Close() File.Delete("C:\Users\mks\Desktop\Newfolder\ro1.mod") File.Delete("C:\Users\mks\Desktop\Newfolder\yo1.mod") File.Delete("C:\Users\mks\Desktop\Newfolder\bo1.mod") File.Delete("C:\Users\mks\Desktop\Newfolder\rs1.mod") File.Delete("C:\Users\mks\Desktop\Newfolder\ys1.mod") File.Delete("C:\Users\mks\Desktop\Newfolder\bs1.mod") For i As Integer = 0 To s.Length - 1 Step 1 If i Mod 1 = 0 Then End If Try Dim rp1 As String = i / 10 & " " & rp.Substring(i, 1) & Environment.NewLine Dim rn1 As String = i / 10 & " -" & rn.Substring(i, 1) & Environment.NewLine Dim yp1 As String = i / 10 & " " & yp.Substring(i, 1) & Environment.NewLine Dim yn1 As String = i / 10 & " -" & yn.Substring(i, 1) & Environment.NewLine Dim bp1 As String = i / 10 & " " & bp.Substring(i, 1) & Environment.NewLine Dim bn1 As String = i / 10 & " -" & bn.Substring(i, 1) & Environment.NewLine byteDatarp1 = Encoding.ASCII.GetBytes(rp1) byteDatarn1 = Encoding.ASCII.GetBytes(rn1) byteDatayp1 = Encoding.ASCII.GetBytes(yp1) byteDatayn1 = Encoding.ASCII.GetBytes(yn1) byteDatabp1 = Encoding.ASCII.GetBytes(bp1) byteDatabn1 = Encoding.ASCII.GetBytes(bn1) wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\ro1.mod", FileMode.Append) wFile.Write(byteDatarp1, 0, byteDatarp1.Length) wFile.Close() wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\rs1.mod", FileMode.Append) wFile1.Write(byteDatarn1, 0, byteDatarn1.Length) wFile1.Close() wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\yo1.mod", FileMode.Append) wFile.Write(byteDatayp1, 0, byteDatayp1.Length) wFile.Close() wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\ys1.mod", FileMode.Append) wFile1.Write(byteDatayn1, 0, byteDatayn1.Length) wFile1.Close() wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\bo1.mod", FileMode.Append) wFile.Write(byteDatabp1, 0, byteDatabp1.Length) wFile.Close() wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\bs1.mod", FileMode.Append) wFile1.Write(byteDatabn1, 0, byteDatabn1.Length) wFile1.Close() Catch ex As ArgumentOutOfRangeException Exit For Finally End Try Next MsgBox("FIlE HAS BEEN PROCEESED")