说明:
下面的脚本显示了如何分割并重组字符串。
No. | 描述 |
1 | 分割一个包含12个字符的字符串为两个含6个字符的字符串:
{ // WINCC:TAGNAME_SECTION_START // syntax: #define TagPro "pro" #define TagInt1 "int1" #define TagInt2 "int2" // next TagID : 1 // WINCC:TAGNAME_SECTION_END // WINCC:PICNAME_SECTION_START // syntax: #define PicNameInAction "PictureName" // next PicID : 1 // WINCC:PICNAME_SECTION_END char array [ MAX_DM_VARTYPE_TEXT_LEN + 1 ]; char szInt [ 2 ] [ 6 + 1 ]; strcpy(array,GetTagChar( TagPro )); sprintf( szInt [ 0 ] , "%6.6s" , &array[0]); sprintf( szInt [ 1 ] , "%6.6s" , &array[6]); SetTagChar( TagInt1 ,szInt [0]); SetTagChar( TagInt2 ,szInt [1]); } |
2 | 重组两个包含6个字符的字符串:
{ // WINCC:TAGNAME_SECTION_START // syntax: #define TagPro "pro" #define TagInt1 "int1" #define TagInt2 "int2" // next TagID : 1 // WINCC:TAGNAME_SECTION_END // WINCC:PICNAME_SECTION_START // syntax: #define PicNameInAction "PictureName" // next PicID : 1 // WINCC:PICNAME_SECTION_END char array [ MAX_DM_VARTYPE_TEXT_LEN + 1 ]; char szInt [ 2 ] [ MAX_DM_VARTYPE_TEXT_LEN + 1 ]; sprintf( array , "%6s%6s", GetTagChar( TagInt1 ), GetTagChar( TagInt2 )); SetTagChar( TagPro , array ); } |
原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc336770.html