#35899 - 2003-01-31 03:09 PM
Re: Trim Speech Marks
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Here is a UDF which should work in all situations. It returns an array containing each field from the line:
Function fnCSV2Array($s) Dim $iIndex,$iLength,$cChar,$iMode,$iArraySize Redim Preserve $fnCSV2Array[0] $iArraySize=0 $iMode=0 ; 1 = in quoted field
$iLength=Len($s) For $iIndex = 1 To $iLength $cChar=SubStr($s,$iIndex,1) If $iMode If $cChar='"' If SubStr($s,$iIndex+1,1)='"' $fnCSV2Array[$iArraySize]=""+$fnCSV2Array[$iArraySize]+$cChar $iIndex=$iIndex+1 Else $iMode=0 EndIf Else $fnCSV2Array[$iArraySize]=""+$fnCSV2Array[$iArraySize]+$cChar EndIf Else Select Case $cChar=',' $iArraySize=$iArraySize+1 Redim Preserve $fnCSV2Array[$iArraySize] Case $cChar='"' $iMode=1 Case "true" $fnCSV2Array[$iArraySize]=""+$fnCSV2Array[$iArraySize]+$cChar EndSelect EndIf Next EndFunction
|
Here is an example of how to use it:
For Each $sElement In fnCSV2Array('The following field contains a comma,"Doe, John"') "<" $sElement "> " Next ?
|
[ 31. January 2003, 15:23: Message edited by: Richard H. ]
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|