I would like to allow our consultant/user to define receipt layout in text file as below. Then I can substitute it actual value and print it out.

Code Block

<<center>><<Company Name>><</center>>

<<underline>>Item Qty Price SubTotal<</underline>><</Header>>
<<ItemCode>> <<Qty>> <<Price>> <<SubTotal>><</Details>>

<<Footer>>Grand Total:<<GrandTotal>><</Footer>>

Thank you, Please come again.

Any ideas

Thank you

Re: Visual C# General Text merge


Could you explain exactly what you mean



Re: Visual C# General Text merge


Try using StringBuilder.Replace.

Something like this. There may be ways to make this more efficient.

Code Block

using (StreamReader reader = File.OpenText("MyReportTemplate.txt"))


StringBuilder report = new StringBuilder(reader.ReadToEnd());

report.Replace("<<Header>>","Put your header here");

report.Replace("<<GrandTotal>>", grandTotal.ToString());

//TODO: Save your report.ToString() to a new file


StringBuilder keeps an internal buffer for manipulating the string, so it can efficiently replace strings multiple times without allocating tons of extra space the way that string.Replace does.

Re: Visual C# General Text merge

In Love With Dotnet


There are many ways to do this. This is basically considered as a reporting task. Following are the options :

1) Crystal Report

2) SRS (SQL Reporting Services)

Other than this, this can also be done using normal win/web form wherein you have to create a kind of template. Dynamic valuse <<>> will be populated via variable. So probably you will have to have user interface through which these values will come in and at the end of transaction, you can populate into your form and print it out. You also have to take care printers to be supported.

Items will have looping. So if you are not using any reporting tool n doing it manually from win/web forms, you will have to create controls at runtime and populate data accordingly.

Hope this will help