星期一, 5月 09, 2011

在c#中正確處理Unicode

程式碼:

string s = "哈\uD950\uDF21高";   Console.WriteLine("string length:" + s.Length);  
TextElementEnumerator textEnum =
   StringInfo.GetTextElementEnumerator(s);   while (textEnum.MoveNext())   {   
   Console.WriteLine("word {0}: {1}",
     textEnum.ElementIndex, 
     textEnum.Current.ToString());  
}
* This source code was highlighted with Source Code Highlighter.

輸出:
string length:4
word 0: 哈
word 1: ??
word 3: 高

重點:

  • UTF-32等同於UCS-4 (Universal Character Set –4 ), 編碼範圍在0~7F FF FF FF
  • UTF-16不等同於UCS-2。USC-2只涵蓋部分USC-4的字元。而UTF-16可以涵蓋所有UTF-32的字元
  • UTF-16利用surrogate機制,讓某些UTF-32的字元以一對UTF-16編碼的形式來表示
  • USC-2跟UTF-16的差別在於有無surrogate機制上
  • .Net使用的char型別存放的是UTF-16

星期二, 1月 25, 2011

Doxgen筆記

格式:

/**
  * @warning A Warning!!
  */

星期一, 1月 10, 2011

在Microsoft Access筆記中

參照到使用者介面物件

  • [Forms]![Questions]![RawData 子表單].Form![answer]

取得目前使用者

星期日, 10月 24, 2010

Visual Studio的編譯會受Windows SDK版本設定的影響

幾個簡單檢視目前Windows SDK版本的方法:

  • 方法一: 開啟Visual Studio Command Prompt, 下echo %windowssdkdir%指令
  • 方法二: 開啟vc專案,找到”Include Directories”之類的設定項目,在編輯畫面的Macros中檢視 $(WindowsSDKDir)

Windows SDK版本設定如果不正確,可能會導致vc專案編譯失敗,出現類似像windows.h找不到的錯誤訊息。

修正方式:

  • 在windows SDK目錄下,使用以下命令來設定(以下命令將SDK版本設定為v7.0A):
    C:\Program Files\Microsoft SDKs\Windows\v7.1\Setup>WindowsSdkVer.exe -version:v7.0A

參考資料

星期二, 8月 10, 2010

嘗試在VS2010中使用C++0x的shared_ptr以及lambda expression搭配STL container

#include <iostream>
#include <vector>
#include <memory>
#include <algorithm>

using namespace std;

class Base{
public:
    int m_i;
    Base(int i):m_i(i) {}
    ~Base(){ cout << m_i << "~Base()" << endl; }
};

class Derived: public Base{
public:
    Derived(int i):Base(i) { }
    ~Derived(){
        cout << "~Derived()" << endl;
    }
};

int main()
{
    vector< shared_ptr<Base> > v;
    v.push_back(shared_ptr<Base>(new Derived(1)));
    v.push_back(shared_ptr<Base>(new Derived(2)));
    sort(v.begin(), v.end(), [](shared_ptr<Base> a, shared_ptr<Base> b){
        return a->m_i > b->m_i;
    });

    for_each(v.begin(), v.end(), [](shared_ptr<Base> a){
        cout << a->m_i << "\t";
    });
    cout << endl;
    return 0;
}

星期四, 7月 08, 2010

莫名其妙的簡繁轉換

葉:叶
舊:旧
盡:尽

星期日, 6月 06, 2010

在VS2010中,指定clean solution或project前執行某些指令

由於vs2010 IDE似乎沒有直接支援這樣設定,因此採用Import Project的方式,以便明確地看出這是額外加上去的指令。

  1. 在 *.vcxproj file中Import Project:
    <Import Project="Extra.targets"/>
  2. 建立Extra.targets file, 內容為:
    <?xml version="1.0" encoding="utf-8"?>
    <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3.   <Target Name="BeforeCppClean">
        <Exec Command="echo Hello World" />
      </Target>
    </Project>

相關資料:

  • C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets and Microsoft.CppClean.targets
  • MSBuild Schema Reference