Reputation: 78
i want to read a text file that Contains
<CustomerName>@CoustomerName</CoustomerName>
<CustomerAddress>@CustomerAddress</CustomerAddress>
<CustomerMobileNo>@CustomerMobileNo</CustomerMobileNo>
<Payment>@Payment</Payment>
Replace this @CoustomerName with Coustomer Name Passes During Run Time
Till then i use this
string readfile = File.ReadAllText(path);
Regex.Replace(readfile , "@CoustomerName ", objProposar.FirstName);
This works But i need to make changes in Coustomer address, mobile no etc How can i do this
Upvotes: 0
Views: 31
Reputation: 13483
If your file is XML - use XML way of doing it, like XDocument, otherwise string.Replace
is a better option:
string readfile = File.ReadAllText(path);
readfile = readfile.Replace("@CoustomerName", objProposar.FirstName);
Upvotes: 0
Reputation: 460238
Why regex, a simple String.Replace
will do the job:
string oldText = File.ReadAllText(path);
string newText = oldText.Replace("@CoustomerName", objProposar.FirstName);
// other ...
File.WriteAllText(path, newText);
Upvotes: 1