Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SplitCSV_ToTable( sCSV )
- -- There is a first comma and then a last.
- local tValues = {}
- local nLastComma_Pos_Dupe = 1
- local nLastComma_Pos = 1
- local nValueLength = 0 -- This will be the difference in comma positions.
- local bFirstRun = true
- local bEndOfString = false
- local cEndCharacter = string.sub( sCSV, string.len( sCSV ), string.len( sCSV ) ) -- Get the last character in the list.
- while not bEndOfString do
- nLastComma_Pos_Dupe = nLastComma_Pos
- -- test,test
- nLastComma_Pos = string.find( sCSV, ",", nLastComma_Pos+1, string.len( sCSV ) )
- if nLastComma_Pos ~= nil then
- nValueLength = nLastComma_Pos - nLastComma_Pos_Dupe
- if bFirstRun then
- -- Handle a single space.
- if string.sub( sCSV, 1, 1 ) == " " then
- tValues[1] = string.sub( sCSV, 2, nValueLength )
- else
- tValues[1] = string.sub( sCSV, 1, nValueLength )
- end
- bFirstRun = false
- else
- if string.sub( sCSV, nLastComma_Pos_Dupe+1, nLastComma_Pos_Dupe+1 ) == " " then
- tValues[#tValues+1] = string.sub( sCSV, nLastComma_Pos_Dupe+2, nValueLength + nLastComma_Pos_Dupe-1 )
- else
- tValues[#tValues+1] = string.sub( sCSV, nLastComma_Pos_Dupe+1, nValueLength + nLastComma_Pos_Dupe-1 )
- end
- end
- else
- -- Get the last character.
- if string.sub( sCSV, nLastComma_Pos_Dupe+1, nLastComma_Pos_Dupe+1 ) == " " then
- tValues[#tValues+1] = string.sub( sCSV, nLastComma_Pos_Dupe+2, string.len( sCSV ) )
- else
- tValues[#tValues+1] = string.sub( sCSV, nLastComma_Pos_Dupe+1, string.len( sCSV ) )
- end
- bEndOfString = true
- return tValues
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement