Anirudha
Anirudha

Reputation: 23

Replace Text inside a bracket with a form field in C#

I want to replace the text inside a [ ] bracket with web form fields in C#, What is the best way to perform it.

"Complaint No [Complaint No] from [PARTY NAME]logged. Please assign Engineer at [SITE ADDRESS]"

Expected Output :- Complaint no 1234 from ABC logged. Please Assign engineer at SiteLocation

Upvotes: 0

Views: 105

Answers (2)

tej
tej

Reputation: 41

I think you can use String.Format().

String.Format("Complaint No {0} from {1} logged. Please assign Engineer at {2}", Complaint_No, Party_Name, Site_Address);

store the data you want to print in Complaint_No, Party_Name, Site_Address these string or if you are retriving it the pass it to the string and use the above fromat.

Upvotes: 2

raulmd13
raulmd13

Reputation: 191

As you don't give information from where the data come from, I cannot be more especific.
I have storaged your data in three differents strings.

string complaint_no = "1234";
string party_name = "ABC";
string site_address = "SiteLocation";
string result = String.Format("Complaint No {0} from {1} logged. Please assign Engineer at {2} \n", complaint_no, party_name, site_address);  

Explanation: The {number} are going to transform into the string with the same number position. You can use variables or raw strings in this positions.

You can try it here online: https://dotnetfiddle.net/eHui4D

Upvotes: 1

Related Questions