Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
LÀM VIỆC với chuỗi Nếu bạn tập tin định dạng với một quy ước đặt tên tiêu chuẩn, bạn có thể phân chia các tên tập tin vào chuỗi con hợp lý có thể được sử dụng sau này trong logic lập trình của bạn. Loại này (INTO lớp học của bạn): | WORKING WITH STRINGS 8 r idsjk i If you format files with a standard naming convention you can split the filename into logical substrings that can be used later in your programming logic. TYPE THIS INTO YOUR CLASS RESULT static void Main string sFileName hri_disney_jan2001_001.jpg string sFileParts new string 4 char cDelim new char 1 char.Parse _ sFileParts sFileName.Split cDelim 4 string string string sPhotoType string sPhotoEvent sFileParts 1 sPhotoDate sFileParts 2 sPhotoIndex sFileParts 3 .Remove 3 4 switch case sPhotoType high resolution image break case tni sPhotoType thumbnail image break default sPhotoType unknown image type break Console.WriteLine The sPhotoType selected was index sPhotoIndex of pictures at sPhotoEvent which was taken sPhotoDate . sFileParts 0 hri C csc SplitString_ai.cs C SplitString_ai.exe The high resolution image selected was index 001 of pictures at disney which was taken jan2001. C -Q Create a string array of size 4. Q Add the Split function to split the image file up into four elements using the underscore _ character for the delimiter. Write the date that the picture was taken by accessing the second element. Lffl Set a debug stop. Press F5 to save build and run the console application. A message appears showing the date the image was taken. 179 JOIN STRINGS The String class provides methods for joining several strings and merging them into one continuous string. The String.Join method lets you join the strings with separators you specify between each string. Joining strings together is common when interacting with relational databases. For example when you build a string that contains the full address for a customer you should not store this entire string in the database. For more efficient use of your database you will normalize the storage of the address into separate fields and or tables. Because the address will be in separate fields when you pull the data from the database and display it on a user interface you will need to .