Hi,
I am developing an app that will import numeric data and export it to various text files using ascii templates. I am basically converting the template file into a single string, replacing application fields in the string with {0}, {1}, etc... and adding the result into an array that is then passed to the String.Format(str_Template, Params()) to provide the final output. I have set it up so the template will use the standard VB.Net formatting syntax.
A simple template example:
{<prt_Mark>:G} {<prt_Qty>:F2} {<prt_Length>:F2} {<prt_Remarks>:G}
If an app field is found in the string, the value is added to the Param() array and the field name {<prt_Mark>:G} is replaced with it's array position resulting in {0:G}.
The final template string will be:
{0:G} {1:F2} {2:F2} {3:G}
And the Params() array will be:
Params(0) = B1001
Params(1) = 10
Params(2) = 120.5
Params(3) = Remarks
The result of String.Format(str_Template, Params()) will be:
B1001 10 120.50 Remarks
This all works really well and i am very happy with the output flexibilty. The problem that i am facing now is a bit more challenging. There are going to be cases where we want to "tweak" the data upon export. The "tweaking" will not happen within the application and i am trying to figure out how to do some simple "tweaking" with the formatting. I have started researching the IFormattable interface but would like to know what people think before diving in.
The "tweaks" that might be required are simple replace and simple calculations. For instance: We might want the part mark to be B_1001 instead of B1001 or we might want the Length (120.50) to be the Length + 10 (130.50). I was thinking that i might be able to find a way to override the format method to include something like this:
{<prt_Length>:F2+10} or {<prt_Length>:F2*10} or {<prt_Mark>:G:Replace(B,B_)}
I guess i am really just wondering if there are already ways to perform calculations within the String.Format method?
I would really appreciate any thoughts or advice on this matter.
Thanks,
Joel
I am developing an app that will import numeric data and export it to various text files using ascii templates. I am basically converting the template file into a single string, replacing application fields in the string with {0}, {1}, etc... and adding the result into an array that is then passed to the String.Format(str_Template, Params()) to provide the final output. I have set it up so the template will use the standard VB.Net formatting syntax.
A simple template example:
{<prt_Mark>:G} {<prt_Qty>:F2} {<prt_Length>:F2} {<prt_Remarks>:G}
If an app field is found in the string, the value is added to the Param() array and the field name {<prt_Mark>:G} is replaced with it's array position resulting in {0:G}.
The final template string will be:
{0:G} {1:F2} {2:F2} {3:G}
And the Params() array will be:
Params(0) = B1001
Params(1) = 10
Params(2) = 120.5
Params(3) = Remarks
The result of String.Format(str_Template, Params()) will be:
B1001 10 120.50 Remarks
This all works really well and i am very happy with the output flexibilty. The problem that i am facing now is a bit more challenging. There are going to be cases where we want to "tweak" the data upon export. The "tweaking" will not happen within the application and i am trying to figure out how to do some simple "tweaking" with the formatting. I have started researching the IFormattable interface but would like to know what people think before diving in.
The "tweaks" that might be required are simple replace and simple calculations. For instance: We might want the part mark to be B_1001 instead of B1001 or we might want the Length (120.50) to be the Length + 10 (130.50). I was thinking that i might be able to find a way to override the format method to include something like this:
{<prt_Length>:F2+10} or {<prt_Length>:F2*10} or {<prt_Mark>:G:Replace(B,B_)}
I guess i am really just wondering if there are already ways to perform calculations within the String.Format method?
I would really appreciate any thoughts or advice on this matter.
Thanks,
Joel