找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1219|回复: 0

[分享] AcString Type

[复制链接]

已领礼包: 859个

财富等级: 财运亨通

发表于 2016-1-28 08:35:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
http://www.private.peterlink.ru/ ... M2007-AcStringe.htm

ObjectARX 2007 以上加入的类,Autocad 下用这个类处理字符串足矣!

This is a continuation of the theme: migration of ARX applications to AutoCAD 2007.
In ObjectARX there is a special class (data type) AcString declared in AcString.h of versions 2006 and 2007 (in ObjectARX 2005 or earlier there is no such a type). Text string declaration when using the class looks like the following one:
AcString str;
This data type is very much alike CString type (from the MFC library) and std::string  (from the standard library, STL) but is different because it allows to operate both on strings containing char symbols and on string containing wchar_t symbols.  The AcString class has constructors creating strings from char type and wchar_t type, e.g.:
AcString sa("String of char");
AcString sw(_T("String of wchar_t"));

With the help of a corresponding constructor one can create an empty string or a string  initialized with a symbol of type char or of type wchar_t.
AcString type assists in conversion between char and wchar_t types, e.g.:
const char *pStrA1 = sa.kszPtr();
or
const char *pStrA2 = sa; // implicitely (const char *)sa; is called
const wchar_t *pStrW1 = sa.kwszPtr();
const wchar_t *pStrW2 = sa; // implicitely (const wchar_t *)sa; is called

Moreover the class has operators/functions for string concatenation, substring search and selection, getting string length, formatting, conversion to number and so on. Using AcString type allows to write the code that  in overwhelming majority of cases will work in AutoCAD 2006 as well as in AutoCAD 2007 and next versions.
As an example, the following expression will work in both versions of AutoCAD:
acedPrompt (AcString("\nPrinting a string"));
You must be careful only while calling the function with a variable number of arguments (e.g. acutPrintf when number of arguments is greater than one, as well as acedCommand, acutBuildList) because compilator cannot understand what type is to be passed. In these cases it is more preferable to use methods AcString::kszPtr() and AcString::kwszPtr() for explicit clarification of data type. On basis of this class it is convenient to make macros for passing required type to functions, e.g.:
#ifndef INC_UNI_H
     #include <AcString.h>
#define INC_UNI_H
   #if defined(ACADR17)
  // Conversion from UNICODE to ANSI
     #define W2C(x) ((const char    *)AcString(x))
  // Conversion from ANSI to UNICODE
     #define C2W(x) ((const wchar_t *)AcString(x))
   #else
     #define W2C(x) (x)
     #define C2W(x) (x)
   #endif
#endif

If for preprocessor in ObjectARX 2006 project the ACADR16 identifier is set or in ObjectARX 2007 project the ACADR17 identifier is set then the lines
char *str1 = "\nPrinting a string <%s>";
char *str2 = "---my string---";
acutPrintf(C2W(str1), C2W(str2));

will be compiled rightly and will work in both versions of AutoCAD.
Similarly the following expression will be compiled without errors and will be normally executed:
acedCommand (RTSTR, C2W("_.LINE"), RTSTR, C2W("0,0"), RTSTR, C2W("10,10"), RTNONE);
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-23 08:36 , Processed in 0.170770 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表