Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Using vb.net 2010 What I'm trying to do is keep the 3 formats for a letter available for changes after the application has been compiled.
For example I have:
strMessage = "Dear " + strClient + vbCrLf + "Thank you for your purchase..."

This works correct and the output looks like it should:
Dear Mr Smith
Thank you for your purchase...

however if I do something like:
strMessage = My.Setting.purchaseMsg

and the value of purchaseMsg in the settings is:
"Dear " + strClient + vbCrLf + "Thank you for your purchase..."

However the output for this looks like:
Dear " + strClient + vbCrLf + "Thank you for your purchase...
Note the missing " at the start and the end.

I'm at a loss right now, so I'm hoping someone has an idea... thanks in advance.
Posted

You can use the String.Format method to format your message and store the string including the format specifier in your settings file.

For example in the settings: "Dear {0} Thank you for your purchase...." and format this with String.Format(purchaseMsg, strClient)
 
Share this answer
 
Comments
MacRaider4 21-Apr-11 15:25pm    
Yeah I would have figured that out in about 15 years... way to make that one easy M$. Thank you very much, I greatly appreciate it!!!!!
Sergey Alexandrovich Kryukov 21-Apr-11 16:04pm    
Correct, my 5.
I also added the explanation of performance aspect of it; please see my Solution.
--SA
One reason to avoid repeated string concatenation ("+") is that fact that the strings are immutable. String are not really concatenated, a new string is created on each operator and initialized to a concatenation of other strings, so it is copied back and forth twice. Performance of such operation is no good. It is especially important not to use concatenation in cycles.

Instead, System.Test.StringBuilder should be used; and string.Format is also good for ad-hoc formatting.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900