Brijm
Lifetime Supporting Member
I recently did a project, where I was parsing CSV files in Crimson3, and thought this program may be of use to some.
Setup a program data type string with two parameters (cstring sText, int nPos) Calling the function with Parameters(test,0) will return the first comma separated variable in string test. The delimiting character can be easily changed as well.
Paste the following in your code:
Setup a program data type string with two parameters (cstring sText, int nPos) Calling the function with Parameters(test,0) will return the first comma separated variable in string test. The delimiting character can be easily changed as well.
Paste the following in your code:
/* cstring CSVSeek(sText,nPos)
Finds Target Position in a CSV string Starting with 0
Returns sText if no "," exists at Pos
*/
int nFrom, nTo,nCount;
int delimiter = ',';
if (nPos == 0) nFrom = 0;
else nFrom = Find (sText,delimiter,nPos-1) + 1;
nTo = Find(sText,delimiter,nPos);
if (nTo == -1) nCount = Len(sText) - nFrom;
else nCount = nTo - nFrom;
if (nFrom == -1) return sText;
else return Mid (sText, nFrom, nCount);