Skip to main content

Posts

Showing posts from September, 2017

String Interpolation in VB .NET

Here shows 2 ways to implement string interpolation, they should be very useful for formatting output string. String.Format Method This method is very common and easy to use for outputting string. Just put the string or variable after first argument. Dim strOutputString As String = "The price of {0} is {1}." Debug.Print(String.Format(strOutputString, "book", "10")) 'The price of book is 10. Of course, passing more arguments is acceptable. Dim strOutputString As String = "The price of {0} is {1}, and buy {2} get {3} free." Debug.Print(String.Format(strOutputString, "book", "10", "2", "1")) 'The price of book is 10, and buy 2 get 1 free. We sometimes may need to design a shared function for general purpose. So, using array should get more flexibility in various cases. Dim strOutputString As String = "The price of {0} is {1}." Dim arrOutputParams As String() = {"book"...