[ANSYS宏]连接任意字符串
来自:ANSYS.net
一个用于连接字符串的宏,输入几个待连接字符串,然后把字符串按顺序连接在一起,并符于指定的变量。如:输入命令“txtconcat,'mychar',2,'an ',' sys' ”,将得到一个变量mychar,其值为’ansys’。个人觉得这是一个很不错的宏应用例子,尤其是其中的宏参数的引用方法,特转出其宏文件内容如下:
/com ### this macro concatenates 2 to 7 strings and removes all blanks and then
/com ### saves it into the variable which was given as arg1 (in quotes)/com ### arguments: arg1 = variable name into which the result is stored, put in quotes
/com ### arguments: arg2 = total number of single strings to be concatenated
/com ### arguments: arg3 through arg9 = single string in quotes, e.g. arg3='an '/com ### attention: depending on the length of a single input string and/or the length
/com ### of the resulting string, the final string ztstring1 may differ from what
/com ### was desired, as the total length is somewhat restricted (approx 31 characters???)/com ### example: << txtconcat,'mychar',2,'an ',' sys' >> would result in mychar='ansys'
/com ### created 2009-01-12 by Martin Herrenbruck
/com ### using Ansys 11.0 (classic)!----------------------------------------------------------------------------!
! concatenate successively each string with the previous ones
!----------------------------------------------------------------------------!*if,arg2,lt,8,then
*set,ztstring1_,arg3 ! collect first string
*do,ztcounter_, 4, arg2 + 2, 1 ! collect second to max. seventh string
*set,ztstring3_,'arg %ztcounter_%' ! results in 'arg 4' or 'arg 5' or 'arg 6' and so on
*set,ztstring3_,strcomp(ztstring3_) ! remove all blanks, so we have 'arg4' or 'arg5' or 'arg6' and so on
*set,ztstring2_,%ztstring3_% ! save the contents of 'arg4' or 'arg5' and so on as char into ztstring2_
*set,ztstring1_,'%ztstring1_% %ztstring2_%' ! concatenate with previous
*enddo
*set,%arg1%,strcomp(ztstring1_) ! remove all blanks from the string
*endif!----------------------------------------------------------------------------!
! print result on the output window
!----------------------------------------------------------------------------!
/gopr
*vwrite, '### macro ','txtconcat says:',' the characterstring ',arg1
%11c %15c %20c %33c
/com ### was saved into variable %arg1%
/com ### end of macro " txtconcat.mac"
/eof
下载:打包下载