Đang chuẩn bị liên kết để tải về tài liệu:
Accelerated VB 2005 phần 6
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Sự xác định định dạng mà chúng tôi đã chọn là "C" để hiển thị các số trong một định dạng tiền tệ. Đối với màn hình hiển thị đầu tiên, bạn sử dụng các ví dụ CultureInfo thuộc các chủ đề hiện tại. Đối với hai sau đây, bạn tạo một CultureInfo cho cả Đức và Nga. | 192 CHAPTER 10 WORKING WITH STRINGS Note In order to build the previous example you ll need to add a reference to the System.Windows.Forms.dll assembly located in the Microsoft.NET Framework V2.0.XXXXX directory. This example displays the strings using the MessageBox type defined in Windows.Forms since the console isn t good at displaying Unicode characters. The format specifier that we ve chosen is C to display the number in a currency format. For the first display you use the CultureInfo instance attached to the current thread. For the following two you create a CultureInfo for both Germany and Russia. Note that in forming the string the System.Double type has used the CurrencyDecimalSeparator CurrencyDecimalDigits and CurrencySymbol properties of the NumberFormatInfo instance returned from the CultureInfo.GetFormat method. Had you displayed a DateTime instance then the DateTime implementation of IFormattable.ToString would have utilized an instance of DateTimeFormatInfo returned from the CultureInfo.GetFormat in a similar way. Console.WriteLine and String.Format Throughout this book you ve seen Console.WriteLine used in the examples. One of the forms of WriteLine that is useful and identical to some overloads of String.Format allows you to build a composite string by replacing format tags within a string with a variable number of parameters passed in. Let s look at a quick example of string format usage Imports System Imports System.Globalization Imports System.Windows.Forms Public Class EntryPoint Shared Sub Main ByVal args As String If args.Length 3 Then Console.WriteLine Please provide 3 parameters Return End If Dim composite As String _ String.Format 0 1 and 2 . args 0 args 1 args 2 Console.WriteLine composite End Sub End Class Here are the results from the previous example Jack Jill and Spot. CHAPTER 10 WORKING WITH STRINGS 193 You can see that a placeholder is delimited by braces and that the number within it is the zero-based index to the following .