udfItemListCsvToTab
str udfItemListCsvToTab (str, str, bln)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfItemListCsvToTab (strCsvList, strDelimiter, blnSaveQuotes)
If strDelimiter == "" Then strDelimiter == "," ; strDelimiter = ";"  european semicolon separated values.
strSurrogate = Num2Char (7) ; Placeholder.
strQuote = '"'
strQuote2 = StrFill (strQuote, 2)
strTabList = ""
strCsvList = StrReplace (strCsvList, strQuote2, strSurrogate) ; Substitute following double Quotes with placeholder.
If ItemCount (strCsvList, strQuote) == 1
   strTabList = StrReplace (strCsvList, strDelimiter, @TAB)
Else
   While strCsvList != ""
      strItem = ItemExtract (1, strCsvList, strQuote)
      strItem = StrReplace (strItem, strDelimiter, @TAB)
      strTabList = StrCat (strTabList, strItem)
      strItem = ItemExtract (2, strCsvList, strQuote)
      If strItem != ""
         If blnSaveQuotes Then strItem = StrCat (strQuote, strItem, strQuote) ; Enclose text items with quotation marks.
         strTabList = StrCat (strTabList, strItem)
      EndIf
      strCsvList = ItemRemove (1, strCsvList, strQuote)
      strCsvList = ItemRemove (1, strCsvList, strQuote)
   EndWhile
EndIf
If blnSaveQuotes Then strQuote = strQuote2
strTabList = StrReplace (strTabList, strSurrogate, strQuote) ; Replace placeholder with one quotation mark.
Return strTabList
;..........................................................................................................................................
; This UDF udfItemListCsvToTab is able to handle strings like
; strCsvList = '111,222,"1a2b, 3ef",,123,"dfdfdf", 111, 222,"""Double""Quotes"'
; Double Quotes in text items are replaced by unique Quote, so the tab delimited string looks like
; strTabList='111|222|1a2b, 3ef||123|dfdfdf|111|222|"Double"Quotes' (with |=@TAB)
;
; Conf:  WinBatch 2002C Beta
; From:  Marty marty+bbs@winbatch.com
; Date:  Friday, May 17, 2002 12:01 AM
; Slightly modified by Detlev Dalitz.20090604.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.
:Test1
strDelim = ","
strCsvList = 'AUTOSTRADE,4711 '
strResultList01 = udfItemListCsvToTab (strCsvList, strDelim, @FALSE) ; `AUTOSTRADE@TAB4711 `
strResultList02 = udfItemListCsvToTab (strCsvList, strDelim, @TRUE)  ; `AUTOSTRADE@TAB4711 `


:Test2
strDelim = ","
strCsvList1 = '"AUTOSTRADE,4711 ",7.3300,-0.1020,7.4000,7.4400,7.3200,2713500'
strCsvList2 = '7.3300,-0.1020,7.4000,7.4400,7.3200,2713500,"AUTOSTRADE,4711 "'
strCsvList3 = '7.3300,-0.1020,7.4000,7.4400,"AUTOSTRADE,4711 ",7.3200,2713500'
strCsvList4 = '7.3300,-0.1020,7.4000,7.4400,7.3200,2713500'
strCsvList5 = '7.3300,-0.1020,7.4000,7.4400,,7.3200,2713500'
strCsvList6 = '"ACMI.MI","AUTOSTRADE,4711 ",7.3300,"6/21/2001","12:22",-0.1020,7.4000,7.4400,7.3200,2713500'

strResultList11 = udfItemListCsvToTab (strCsvList1, strDelim, @FALSE) ; `AUTOSTRADE,4711 @TAB7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TAB7.3200@TAB2713500`
strResultList12 = udfItemListCsvToTab (strCsvList2, strDelim, @FALSE) ; `7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TAB7.3200@TAB2713500@TABAUTOSTRADE,4711 `
strResultList13 = udfItemListCsvToTab (strCsvList3, strDelim, @FALSE) ; `7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TABAUTOSTRADE,4711 @TAB7.3200@TAB2713500`
strResultList14 = udfItemListCsvToTab (strCsvList4, strDelim, @FALSE) ; `7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TAB7.3200@TAB2713500`
strResultList15 = udfItemListCsvToTab (strCsvList5, strDelim, @FALSE) ; `7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TAB@TAB7.3200@TAB2713500`
strResultList16 = udfItemListCsvToTab (strCsvList6, strDelim, @FALSE) ; `ACMI.MI@TABAUTOSTRADE,4711 @TAB7.3300@TAB6/21/2001@TAB12:22@TAB-0.1020@TAB7.4000@TAB7.4400@TAB7.3200@TAB2713500`

strResultList21 = udfItemListCsvToTab (strCsvList1, strDelim, @TRUE)  ; `"AUTOSTRADE,4711 "@TAB7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TAB7.3200@TAB2713500`
strResultList22 = udfItemListCsvToTab (strCsvList2, strDelim, @TRUE)  ; `7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TAB7.3200@TAB2713500@TAB"AUTOSTRADE,4711 "`
strResultList23 = udfItemListCsvToTab (strCsvList3, strDelim, @TRUE)  ; `7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TAB"AUTOSTRADE,4711 "@TAB7.3200@TAB2713500`
strResultList24 = udfItemListCsvToTab (strCsvList4, strDelim, @TRUE)  ; `7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TAB7.3200@TAB2713500`
strResultList25 = udfItemListCsvToTab (strCsvList5, strDelim, @TRUE)  ; `7.3300@TAB-0.1020@TAB7.4000@TAB7.4400@TAB@TAB7.3200@TAB2713500`
strResultList26 = udfItemListCsvToTab (strCsvList6, strDelim, @TRUE)  ; `"ACMI.MI"@TAB"AUTOSTRADE,4711 "@TAB7.3300@TAB"6/21/2001"@TAB"12:22"@TAB-0.1020@TAB7.4000@TAB7.4400@TAB7.3200@TAB2713500`


:Test3
strMsgText = "Demo: udfItemListCsvToTab (strCsvList, strDelimiter, blnSaveQuotes)"
strDelim = ","
strCsvList = '111,222,"1a2b, 3ef",,123,"dfdfdf",111,222,"""Double""Quotes"'

strTabList1 = udfItemListCsvToTab (strCsvList, strDelim, @FALSE) ; `111@TAB222@TAB1a2b, 3ef@TAB@TAB123@TABdfdfdf@TAB111@TAB222@TAB"Double"Quotes`
strAskList1 = AskItemlist (strMsgText, strTabList1, @TAB, @UNSORTED, @EXTENDED)

strTabList2 = udfItemListCsvToTab (strCsvList, strDelim, @TRUE)  ; `111@TAB222@TAB"1a2b, 3ef"@TAB@TAB123@TAB"dfdfdf"@TAB111@TAB222@TAB"""Double""Quotes"`
strAskList2 = AskItemlist (strMsgText, strTabList2, @TAB, @UNSORTED, @EXTENDED)

Exit