2 new attempts (similar engine with vl-string-position):
(defun ALE_StringSubstAll (NewStr PatStr InpStr SttPos / NewLen)
(cond
( (= "" PatStr) InpStr )
( (setq NewLen (strlen NewStr))
(while (setq SttPos (vl-string-search PatStr InpStr SttPos))
(setq
InpStr (vl-string-subst NewStr PatStr InpStr SttPos)
SttPos (+ SttPos NewLen)
)
)
InpStr
)
)
)
(defun ALE_String_CdfToList (InpStr CarDlm / SttPos EndPos TmpStr OutLst TmpElm)
(setq
CarDlm (ascii CarDlm) SttPos 0
EndPos (vl-string-position CarDlm InpStr)
)
(while EndPos
(cond
( (wcmatch (setq TmpElm (substr InpStr (1+ SttPos) (- EndPos SttPos))) "\"*\"")
(setq OutLst
(cons
(ALE_StringSubstAll "\"" "\"\"" (substr TmpElm 2 (- (strlen TmpElm) 2)) 0)
OutLst
)
)
)
( (wcmatch TmpElm "\"*") (setq TmpStr (substr TmpElm 2)) )
( TmpStr
(setq OutLst
(cons
(strcat TmpStr (chr CarDlm) (substr TmpElm 1 (- (strlen TmpElm) 1)))
OutLst
)
TmpStr nil
)
)
( T (setq OutLst (cons TmpElm OutLst)) )
)
(setq SttPos (1+ EndPos) EndPos (vl-string-position CarDlm InpStr SttPos))
)
(reverse
(cons
(cond
( (wcmatch (setq TmpElm (substr InpStr (1+ SttPos))) "\"*\"")
(ALE_StringSubstAll "\"" "\"\"" (substr TmpElm 2 (- (strlen TmpElm) 2)) 0)
)
( (wcmatch TmpElm "\"*")(setq TmpStr (substr TmpElm 2)) )
( TmpStr (strcat TmpStr (chr CarDlm) (substr TmpElm 1 (- (strlen TmpElm) 1))) )
( T TmpElm )
)
OutLst
)
)
)
(defun ALE_String_CdfToListFE (InpStr CarDlm / SttPos EndPos TmpLst TmpStr TmpPos OutLst)
(setq
CarDlm (ascii CarDlm) SttPos 0
EndPos (vl-string-position CarDlm InpStr)
)
(while EndPos
(setq
TmpLst (cons (substr InpStr (1+ SttPos) (- EndPos SttPos)) TmpLst)
SttPos (1+ EndPos) EndPos (vl-string-position CarDlm InpStr SttPos)
)
)
(foreach ForElm (cons (substr InpStr (1+ SttPos)) TmpLst)
(cond
( (wcmatch ForElm "\"*\"")
(setq TmpPos 0 ForElm (substr ForElm 2 (- (strlen ForElm) 2)))
(while (setq TmpPos (vl-string-search "\"\"" ForElm TmpPos))
(setq
ForElm (vl-string-subst "\"" "\"\"" ForElm TmpPos)
TmpPos (1+ TmpPos)
)
)
(setq OutLst (cons ForElm OutLst))
)
( (wcmatch ForElm "*\"")
(setq TmpStr (substr ForElm 1 (- (strlen ForElm) 1)))
)
( TmpStr
(setq OutLst
(cons
(strcat (substr ForElm 2) (chr CarDlm) TmpStr)
OutLst
)
TmpStr nil
)
)
( T (setq OutLst (cons ForElm OutLst)) )
)
)
OutLst
)
Test:
Comando: (setq str "\"abc,123\",\"\"\"ABC\"\"\",\"abc\"\"ABC\"\"123\"")
"\"abc,123\",\"\"\"ABC\"\"\",\"abc\"\"ABC\"\"123\""
Comando: (ALE_String_CdfToList str ",")
("abc,123" "\"ABC\"" "abc\"ABC\"123")
Comando: (ALE_String_CdfToListFE str ",")
("abc,123" "\"ABC\"" "abc\"ABC\"123")
Comando: (LM:csv->lst str 44 0)
("abc,123" "\"ABC\"" "abc\"ABC\"123")
Comando: (setq str "a, b, c,\"John \"\"The Baptist\"\" Smith\",4,5,6")
"a, b, c,\"John \"\"The Baptist\"\" Smith\",4,5,6"
Comando: (ALE_String_CdfToList str ",")
("a" " b" " c" "John \"The Baptist\" Smith" "4" "5" "6")
Comando: (ALE_String_CdfToListFE str ",")
("a" " b" " c" "John \"The Baptist\" Smith" "4" "5" "6")
Comando: (LM:csv->lst str 44 0)
("a" " b" " c" "John \"The Baptist\" Smith" "4" "5" "6")
Comando: (setq str "552.32,\"Smith, John\",42,350,a,b,c,d")
"552.32,\"Smith, John\",42,350,a,b,c,d"
Comando: (ALE_String_CdfToList str ",")
("552.32" "Smith, John" "42" "350" "a" "b" "c" "d")
Comando: (ALE_String_CdfToListFE str ",")
("552.32" "Smith, John" "42" "350" "a" "b" "c" "d")
Comando: (LM:csv->lst str 44 0)
("552.32" "Smith, John" "42" "350" "a" "b" "c" "d")
Comando: (setq str "\"Smith,John\",\"\"\"The Baptist\"\"\"")
"\"Smith,John\",\"\"\"The Baptist\"\"\""
Comando: (ALE_String_CdfToList str ",")
("Smith,John" "\"The Baptist\"")
Comando: (ALE_String_CdfToListFE str ",")
("Smith,John" "\"The Baptist\"")
Comando: (LM:csv->lst str 44 0)
("Smith,John" "\"The Baptist\"")
/[code]