恭喜,你发布的帖子
发布于 2025-01-17 23:43:55
5楼
再介绍一种使用指令”Strg_TO_Chars+SPLIT“的实现方法,用的variant比较多,适用于读取字符串中的多个子字符串,如楼主的问题,直接分解成4个子字符串,只需要输出第3个子字符串即可;缺点就是占用DB空间比较多。
代码如下,
//////////////////////////////////////////////////////////
//String-->arrayChars-->split
REGION initialization
#tempStr_source := #iStr_source;
#tempInt_moveResult1 := MOVE_BLK_VARIANT(SRC := #iVar_emptyChars, COUNT := #cUDInt_stringMax, SRC_INDEX := #cDInt_zero, DEST_INDEX := #cDInt_zero, DEST => #ioArr_chars);//clear buffer
#tempInt_sourceLength := LEN(#tempStr_source);
END_REGION
REGION logic
Strg_TO_Chars(Strg := #tempStr_source,
pChars := #cDInt_zero,
Cnt => #tempInt_sourceLength,
Chars := #ioArr_chars);
#oInt_splitResult := SPLIT(Mode := #iDW_mode, RecSeparator := #iVar_recSeparator, EndSeparator := #iVar_endSeparator, SrcArray := #ioArr_chars, Count => #oUdint_count, DstStruct := #ioArr_desStruct, Position := #statUdint_position);
#tempInt_moveResult2 := MOVE_BLK_VARIANT(SRC := #ioArr_desStruct, COUNT := #cUDInt_one, SRC_INDEX := #cDInt_two, DEST_INDEX := #cDInt_zero, DEST => #tempStr_substring);//copy the third split string to temp
#statUdint_position := #cUDInt_zero;//clear position value otherwise it will not work again when source string has changed
END_REGION
REGION output
#oStr_substring := #tempStr_substring;
END_REGION
请填写推广理由:
分享
只看
楼主