ArticleDirectory
- Preface
- Function 1: Simplified Conversion
- Function 2: Time Difference Calculation
- Conclusion
Preface
All those who have done VB development know that there are some good functions in VB. net, but Microsoft. visualBasic. the DLL provides us with the functions to use these functions (these functions can be used the same without VB)
Here are two main topics: one isSimplified ConversionAnd the other isCalculation time differenceI believe everyone has a way to implement these two functions, but what I want to talk about today is just one sentence.CodeThese two functions are implemented!
Function 1: Simplified Conversion
First, you must reference Microsoft. VisualBasic. dll.
UsingMicrosoft. VisualBasic;StringSTR ="Sorrow";//Simplified to traditional ChineseSTR = strings. strconv (STR, vbstrconv. traditionalchinese,1033);//Traditional to simplifiedSTR = strings. strconv (STR, vbstrconv. simplifiedchinese,1033);
String. strconv description:
The first parameter is the string to be converted;
The second parameter is the enumerated value of the font to be converted;
The third parameter is the final encoding format (localeid) after text conversion );
1028 traditional Chinese
1033 ASCII
Simplified Chinese 2052
Why do I use 1033 for both traditional and simplified to traditional Chinese?
First, we must first know that some simplified Chinese characters do not have any character in Traditional Chinese. In this case, the displayed word is "? .
Because the "country" of 2052 is already in simplified Chinese, when it is converted to traditional Chinese, its encoding is less than 1028, so it will be a question mark.
The best way is to use en-us as the encoding format. After en-US is used as the final encoding format and Asian characters are used, Unicode is used as the storage encoding format. The storage format of string is the same as that of. net. This solves the problem!
Therefore, when performing simplified conversion, set the third parameter to 1033.
Function 2: Time Difference Calculation
I believe that we all have two time differences for computing, which may be the number of days, hours, minutes, or seconds for calculating the difference. We can use a single code to implement this.
UsingMicrosoft. VisualBasic;//Dt = 50LongDt = dateandtime. datediff (dateinterval. Hour, datetime. Now, datetime. Now. addhours (50));
Dateandtime. datediff description:
The first parameter is the enumerated value in the form of the expected time difference. It can be days, hours, minutes, seconds, etc.
The second parameter is the subtraction time value;
The third parameter is the time value to be subtracted;
Conclusion
The above two functions seem very simple, but it is still quite troublesome to implement them without Microsoft. VisualBasic. dll. It is convenient and accurate to implement them using the above methods! If you think it is good, we recommend it!