.net - Replace DB parameters in a string from a textfile -


i writing code read string text file , change dbnames parameter (för surrounded asterisks) different name starts newdb + textbox.text. want change domaindb domain + txtbox.text

my current code searches specific word using string.startswith. i'm looking way read values need change based on comma separation.

here's current dirty code: (it works, i'm looking way make more dynamic)

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() each line in originalfilelines     dim arr = line.split(",")     dim newline new stringbuilder() '    arr(6) = datadb '    sb.appendline(string.join(",", arr)) 'next  each word in arr     if word.startswith("datadb")        newline.append(",newdb" + txtorgid.text.toupper) 'change "datadb%" "newdatadb{txtbox.txt}"      elseif word.contains("*")           newline.append(",*" + txtservername.text) 'change "%*%" "*{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) 

actual lines inside 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 

try this:

dim databases new list(of string)() dim words() string dim txtlines() string = file.readalllines(sfilepath)  each sline string in txtlines     words = sline.split(","c)     words(6) = newdb + textbox.text     sline = string.join(",", words) next  file.writealllines(sfilepath, txtlines) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -