;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfStrGetItemLenMax (strItemList, strDelimiter) If strItemList == "" Then Return 0 intItemCount = ItemCount (strItemList, strDelimiter) If StrLen (strItemList) == intItemCount - 1 Then Return 0 @L = Num2Char (1) @R = Num2Char (2) strItemList = @L : StrReplace (strItemList, strDelimiter, @R : @L) : @R intStrLen = StrLen (strItemList) hdlBB = BinaryAlloc (intStrLen) BinaryPokeStr (hdlBB, 0, StrClean (strItemList, @R : @L, " ", @TRUE, 2)) intItemLenMax = 0 While BinaryEodGet (hdlBB) intItemLen = BinaryIndex (hdlBB, 1, @R, @FWDSCAN) - 1 intItemLenMax = Max (intItemLenMax, intItemLen) intReplace = BinaryReplace (hdlBB, @L : StrFill (" ", intItemLen) : @R, "", @TRUE) EndWhile hdlBB = BinaryFree (hdlBB) Return intItemLenMax ;.......................................................................................................................................... ; This UDF "udfStrGetMaxItemLen" returns the length (byte size) of the longest item in an itemlist. ; ; Detlev Dalitz.20010714.20090426.20090702. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfStrGetItemLenMax_2 (strItemList, strDelimiter) If strItemList == "" Then Return 0 intItemCount = ItemCount (strItemList, strDelimiter) If StrLen (strItemList) == intItemCount - 1 Then Return 0 @L = Num2Char (1) @R = Num2Char (2) strItemList = @L : StrReplace (strItemList, strDelimiter, @R : @L) : @R strItemList = StrClean (strItemList, @R : @L, " ", @TRUE, 2) intItemLenMax = 0 While strItemList != "" intItemLen = StrScan (strItemList, @R, 2, @FWDSCAN) - 2 intItemLenMax = Max (intItemLenMax, intItemLen) strItemList = StrReplace (strItemList, @L : StrFill (" ", intItemLen) : @R, "") EndWhile Return intItemLenMax ;.......................................................................................................................................... ; This UDF "udfStrGetMaxItemLen" returns the length (byte size) of the longest item in an itemlist. ; ; Detlev Dalitz.20090512.20090702. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. intTicksSum1 = 0 intTicksSum2 = 0 strFilename1 = IntControl (1004, 0, 0, 0, 0) ; Use this file as test input. strFilename2 = DirHome () : "wil.clr" ; Use "wil.clr" file as test input. Exclusive (@ON) For intTestLoop = 1 To 10 intTicksStart = GetTickCount () intLineLengthMax11 = udfStrGetItemLenMax (StrReplace (FileGet (strFilename1), @CRLF, @LF), @LF) intLineLengthMax12 = udfStrGetItemLenMax (StrReplace (FileGet (strFilename2), @CRLF, @LF), @LF) intTicksStop = GetTickCount () intTicksSum1 = intTicksSum1 + intTicksStop - intTicksStart intTicksStart = GetTickCount () intLineLengthMax21 = udfStrGetItemLenMax_2 (StrReplace (FileGet (strFilename1), @CRLF, @LF), @LF) intLineLengthMax22 = udfStrGetItemLenMax_2 (StrReplace (FileGet (strFilename2), @CRLF, @LF), @LF) intTicksStop = GetTickCount () intTicksSum2 = intTicksSum2 + intTicksStop - intTicksStart Next Exclusive (@OFF) intTicksSum = intTicksSum1 + intTicksSum2 intPct1 = 100 * intTicksSum1 / intTicksSum intPct2 = 100 * intTicksSum2 / intTicksSum strMsgTitle = "Demo: udfStrGetItemLenMax (strItemList, strDelimiter)" strMsgText = "BinBuf version results: " : @LF : intLineLengthMax11 : @LF : intLineLengthMax12 strMsgText = strMsgText : @LF : @LF : "String version results: " : @LF : intLineLengthMax21 : @LF : intLineLengthMax22 strMsgText = strMsgText : @LF : @LF : "BinBuf version ticks: " : intTicksSum1 : @LF : "String version ticks: " : intTicksSum2 strMsgText = strMsgText : @LF : @LF : "BinBuf version performance pct.: " : intPct1 : @LF : "String version performance pct.: " : intPct2 Message (strMsgTitle, strMsgText) ClipPut (strMsgTitle : @LF : @LF : strMsgText) Exit ;------------------------------------------------------------------------------------------------------------------------------------------ ; Demo: udfStrGetItemLenMax (strItemList, strDelimiter) ; ; BinBuf version results: ; 139 ; 61 ; ; String version results: ; 139 ; 61 ; ; BinBuf version ticks: 1657 ; String version ticks: 2750 ; ; BinBuf version performance pct.: 37 ; String version performance pct.: 62 ;------------------------------------------------------------------------------------------------------------------------------------------