关于CATUnicodeString

本文原作者:Luca Gutierrez,经授权后转发

扫码关注微信公众号:CATIA二次开发助手

扫码关注微信公众号:CATIA二次开发助手

CATUnicodeString是CAA的跨语言字符串解决方案,是CATIA内部广泛采用的字符串类型,推荐所有的开发者使用,从其名字即可得知,CATUnicodeString采用Unicode编码,Unicode被称之为万国码,可以为英文、中文、东欧语系、日文、韩文等所有语言文字字符进行编码。Unicode编码规定每个字符占用两个字节。

获取字符串方式


  • GetLengthInChar
  • GetLengthInByte
  1. 1int lengthInByte = 0
  2. 2int lengthInChar = 0
  3. 3CATUnicodeString testStr = "中国NB"
  4. 4lengthInByte = testStr.GetLengthInByte(); 
  5. 5lengthInChar = testStr.GetLengthInChar(); 
  6. 6cout << testStr << " GetLengthInByte =" << lengthInByte << endl
  7. 7cout << testStr << " GetLengthInChar =" << lengthInChar << endl
如上例,“中国”采用4个字节编码,“NB”采用2个字节编码,所以GetLengthInByte的结果为6。GetLengthInChar的结果为4,意为字符串包含的字符数量。

类型转换


  • CATUnicodeString转换到 wchar_t
  1. 1CATUnicodeString testStr = "中国NB"
  2. 2wchar_t *wStr = new wchar_t[100]; 
  3. 3testStr.ConvertToWChar(wStr); 
  • wchar_t 转换到CATUnicodeString
  1. 1CATUnicodeString testStr; 
  2. 2testStr.BuildFromWChar(L"中国NB"); 
  • CATUnicodeString 转 double
  1. 1CATUnicodeString testStr = "3.1415"
  2. 2double value = 0
  3. 3testStr.ConvertToNum(&value); 
  • double 转CATUnicodeString
  1. 1CATUnicodeString testStr = ""
  2. 2double value = 3.1415
  3. 3testStr.BuildFromNum(value);