VS2012spa
多字節字符集code
Edit Control文本框設置成多行(右鍵屬性-Multiline改成true)orm
啓用回車Enter(右鍵屬性-Want Return改成true)blog
添加水平滾動條(右鍵屬性-Horizontal Scroll改成true)字符串
添加垂直滾動條(右鍵屬性-Vertical Scroll改成true)it
1 void CMFCApplication1Dlg::OnBnClickedButtonCount() 2 { 3 // TODO: 在此添加控件通知處理程序代碼 4 5 //得到文本框裏的文本 6 CString strInput; 7 GetDlgItemText(IDC_EDIT_INPUT, strInput); 8 9 //得到字符串的長度 10 int nLen = strInput.GetLength(); 11 12 //判斷字符是中文仍是英文 13 int nCount = 0; 14 for (int i = 0; i < nLen; i++) 15 { 16 //若是有一個是中文,那麼字符就會大於7f 17 if ((BYTE)strInput[i] > 0x7f) 18 { 19 ++i;//略過中文 20 } 21 nCount++;//個數 22 } 23 24 //輸出 25 CString strOutput; 26 strOutput.Format(_T("字符串長度:%d, 字符個數:%d"), nLen, nCount); 27 SetDlgItemText(IDC_STATIC_OUTPUT, strOutput); 28 }
Caesar盧尚宇io
2021年1月4日class