顯示具有 ANSII 標籤的文章。 顯示所有文章
顯示具有 ANSII 標籤的文章。 顯示所有文章

2018年6月4日 星期一

[C#]字串轉換成Ascii ,再分割4個字元一組

// Create two different encodings.
 Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
 
// Convert the string into a byte array.
byte[] unicodeBytes = unicode.GetBytes(FileName_Main);
 
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
int result = Convert.ToInt16(Math.Ceiling(asciiBytes.Length / 4.0));
for (int i = 0; i < result; i++)
   {
       int Reg =  i;
       Int32 idata = BitConverter.ToInt32(asciiBytes, i * 4);
   }
測試環境:VS2015 C#.NET

[C++]UNICODE字符串轉換為ansi字符串

//UNICODE字符串轉換為ansi字符串
PTCHAR ptszText = TEXT("UNICODE字符串轉換為ansi字符串!");
int cbMultiByte = WideCharToMultiByte(CP_ACP, 0, ptszText, -1, NULL, 0, NULL, NULL);
char *pszText = NULL;
pszText = new char[cbMultiByte];
WideCharToMultiByte(CP_ACP, 0, ptszText, -1, pszText, cbMultiByte, NULL, NULL);
delete[] pszText;

//Cstring轉ansii
CString csText = L"UNICODE字符串轉換為ansi字符串!";
int iByte = WideCharToMultiByte(CP_ACP, 0, csText, -1, NULL, 0, NULL, NULL);
char *chText = NULL;
chText = new char[iByte];
WideCharToMultiByte(CP_ACP, 0, csText, -1, chText, cbMultiByte, NULL, NULL);
delete[] pszText;

測試環境:VS2015 MFC

[SQL]顯示千分位與小數顯示

  CONVERT ( data_type [ ( length ) ] , expression [ , style ] ) CONVERT style參數說明 1  (expression為 money 或 smallmoney型別): 0 : 預設,保留小數位後兩位,並四捨...