udfStrCompose (sString, sComposeList, sDelimiter)
;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfstrcompose",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfstrcompose

#DefineFunction udfStrCompose (sString, sComposeList, sDelimiter)
If (sComposeList == "") Then Return (sString)
sErrMsg = "*** udfStrCompose: Bad parameter sComposeList ***"
iCount = ItemCount(sComposeList,sDelimiter)
If (iCount mod 2) Then Return (sErrMsg)
sComposeStr = ""
iCount = iCount/2
For ii=1 To iCount
   vItem1 = ItemExtract(ii+ii-1,sComposeList,sDelimiter)
   vItem2 = ItemExtract(ii+ii  ,sComposeList,sDelimiter)
   If !IsInt(vItem2) Then Return (sErrMsg)
   If IsInt(vItem1)
      iLen = Max(1+vItem2-vItem1,1)
      sComposeStr = StrCat(sComposeStr,StrFix(StrSub(sString,vItem1,iLen)," ",iLen))
   Else
      For id=1 To 3
         sDelim = StrSub(""",',`",id,1)
         vItem = ItemExtract(2,vItem1,sDelim)
         If (StrCat(sDelim,vItem,sDelim) == vItem1)
            vItem1 = vItem
            Break
         EndIf
      Next
      vItem = vItem1
      For in=2 To vItem2
         vItem = StrCat(vItem,vItem1)
      Next
      sComposeStr = StrCat(sComposeStr,vItem)
   EndIf
Next
Return (sComposeStr)
;..........................................................................................................................................
; Returns a string which is composed as defined in sComposeList.
; Example:
;
; csDelim = ","
; clist = ""
; clist = Iteminsert(StrCat( ": "      ,csDelim, "1"  ),-1,clist,csDelim) ;  append ': '     times 1
; clist = Iteminsert(StrCat( "#35"     ,csDelim, "1"  ),-1,clist,csDelim) ;  append '#35'    times 1
; clist = Iteminsert(StrCat( "'4711'"  ,csDelim, "2"  ),-1,clist,csDelim) ;  append '4711'   times 2
; clist = Iteminsert(StrCat( "2"       ,csDelim, "5"  ),-1,clist,csDelim) ;  append column 2 thru 5
; clist = Iteminsert(StrCat( " "       ,csDelim, "5"  ),-1,clist,csDelim) ;  append blank    times 5
; clist = Iteminsert(StrCat( "2"       ,csDelim, "3"  ),-1,clist,csDelim) ;  append column 2 thru 3
; clist = Iteminsert(StrCat( "."       ,csDelim, "1"  ),-1,clist,csDelim) ;  append '.'      times 1
; clist = Iteminsert(StrCat( "4"       ,csDelim, "5"  ),-1,clist,csDelim) ;  append column 4 thru 5
; clist = Iteminsert(StrCat( "%%"      ,csDelim, "1"  ),-1,clist,csDelim) ;  append symbol percent times 1
; clist = Iteminsert(StrCat( "%@crlf%" ,csDelim, "2"  ),-1,clist,csDelim) ;  append @crlf    times 2
; clist = Iteminsert(StrCat( ";"""     ,csDelim, "1"  ),-1,clist,csDelim) ;  append ';"'     times 1
; clist = Iteminsert(StrCat( "%@tab%"  ,csDelim, "1"  ),-1,clist,csDelim) ;  append @tab     times 1
; clist = Iteminsert(StrCat( "- . "    ,csDelim, "20" ),-1,clist,csDelim) ;  append '- . '   times 20
; clist = Iteminsert(StrCat( """"      ,csDelim," 1"  ),-1,clist,csDelim) ;  append '"'      times 1
; clist = Iteminsert(StrCat( "%@crlf%" ,csDelim, "1"  ),-1,clist,csDelim) ;  append @crlf    times 1
;
; Composing the tag string looks somewhat cryptic, but don't worry, be happy.
; - Use always sets of two elements: 'from,thru' or 'text,multiplier'.
; - Use tupel (n,m)   for extracting chars from sString out of columns n to m.
; - Use tupel (abc,n) to fill new text "abc" n-times into the composed string,
;   as an alternative: use tupel ('a b c',n) to fill in new text "a b c" n-times.
;..........................................................................................................................................
; Detlev Dalitz.20010716
;..........................................................................................................................................
#EndFunction

:skip_udfstrcompose
;------------------------------------------------------------------------------------------------------------------------------------------



; --- test ---

:test1
sString = "All messages in all conferences have been marked as read."
sComposeList = "43,46,' --> ',2,5,12, ,2,33,36, ,2,44,44,2,3, ,2,38,41, ,2,38,38,55,56, ,1,<,1,-,5"
sComposeStr = udfStrCompose(sString,sComposeList,",")
sMsgTitle = "Demo udfStrCompose (sString, sComposeList, sDelimiter)"
sMsgText  = StrCat('sString = "',sString,'"',@CRLF)
sMsgText  = StrCat(sMsgText,'sComposeList = "',sComposeList,'"',@CRLF)
sMsgText  = StrCat(sMsgText,'sComposeStr = "',sComposeStr,'"')
Message(sMsgTitle,sMsgText)
; ==> "mark -->  --> messages  have  all  been  bad <-----"



:test2
sString = "Demo with bad formatted sComposeList."

; sComposeList is not ok: 3 and a half tupel, odd number of items
sComposeList = "1,5,33,34,10,13,."

; sComposeList is ok: 4 tupel, even number of items
; sComposeList = "1,5,33,34,10,13,.,1"

sComposeStr = udfStrCompose(sString,sComposeList,",")

sMsgTitle = "Demo udfStrCompose (sString, sComposeList, sDelimiter)"
sMsgText  = StrCat('sString = "',sString,'"',@CRLF)
sMsgText  = StrCat(sMsgText,'sComposeList = "',sComposeList,'"',@CRLF)
sMsgText  = StrCat(sMsgText,'sComposeStr = "',sComposeStr,'"')
Message(sMsgTitle,sMsgText)

Exit
;------------------------------------------------------------------------------------------------------------------------------------------