我正在编写代码以从文本文件中读取字符串,然后将DBnames
参数(由星号包围)更改为以NEWDB + textBox.Text
. DOMAINDB
我也想改成DOMAIN + txtbox.Text
我当前的代码仅使用string.StartsWith
. 但我正在寻找一种方法来读取我需要根据逗号分隔更改的值。
这是我当前的脏代码:(它有点工作,但我正在寻找一种让它更动态的方法)
CurrentFilePath = NextFilePath(FilePaths, FileEnum) 'defined in previous section
OriginalFileLines = File.ReadAllLines(CurrentFilePath) 'defined in previous section
NewFileLines.Clear()
Dim DataDB = "NEWDB" + txtbox.Text.ToUpper()
Dim DomainDB = "DOMAIN" + txtbox.Text.ToUpper()
Dim sb = New StringBuilder()
For Each line In OriginalFileLines
Dim arr = line.Split(",")
Dim NewLine As New StringBuilder()
' arr(6) = DataDB
' sb.AppendLine(String.Join(",", arr))
'Next
For Each word In arr
If word.StartsWith("DATADB") Then
NewLine.Append(",NEWDB" + txtOrgID.Text.ToUpper) 'Change "DATADB%" to "NEWDATADB{txtbox.txt}"
ElseIf word.Contains("*") Then
NewLine.Append(",*" + txtServerName.Text) 'Change "%*%" to "*{ServerName}"
Else
NewLine.Append(IIf(Array.IndexOf(arr, word) > 0, ",", "") + word) 'Comma if not first word
End If
Next
NewFileLines.Add(NewLine.ToString)
File.WriteAllLines(CurrentFilePath, NewFileLines.ToArray)
TextFile 中的实际行:
SSA,SystemA,,YES,YES,*SERVERNAME,**DATADB**,Admin,Passw0rd!,,,MS-SQL
SSB,SystemB,,NO,YES,*SERVERNAME,**DOMAINDB**,Admin,Passw0rd!,,,MS-SQL
SSC,SystemC,,YES,YES,*SERVERNAME,**DOMAINDB**,Admin,Passw0rd!,,,MS-SQL