Scanning for Commas in a string
Posted: Thu Oct 13, 2011 5:05 am
I have a query that I need help with as my mind has hit a blank.
I have a string that contains many elements and values and Iām trying extract the elements and Values from the string using the Scan and While functions in TI with no success.
Basically the first part of the string is an Element eg ā 200000ā then after the Element is the Count eg 1. And then it repeats many times with in the string. The String looks like this.
Product List
200000:1,200001:1,300032:1
200000:1,200025:1,300002:1,250001:1
If anyone has any suggestions as to the best way to Extract the Element and Assign the counts that would be great. At the moment Ive hit a blank.
What I have at the moment after so many changes is
nLen = Long (dpg_ProductList);
nIndex =Scan (',',dpg_ProductList);
While (nIndex < nLen);
vElement = SUBST(dpg_ProductList, 1, SCAN(':', dpg_ProductList) - 1) ;
vCount =SUBST(dpg_ProductList, SCAN(':', dpg_ProductList) + 1, LONG(dpg_ProductList)) ;
nIndex = nIndex +1 ;
END;
AsciiOutput('my.txt',vElement,vCount);
I have a string that contains many elements and values and Iām trying extract the elements and Values from the string using the Scan and While functions in TI with no success.
Basically the first part of the string is an Element eg ā 200000ā then after the Element is the Count eg 1. And then it repeats many times with in the string. The String looks like this.
Product List
200000:1,200001:1,300032:1
200000:1,200025:1,300002:1,250001:1
If anyone has any suggestions as to the best way to Extract the Element and Assign the counts that would be great. At the moment Ive hit a blank.
What I have at the moment after so many changes is
nLen = Long (dpg_ProductList);
nIndex =Scan (',',dpg_ProductList);
While (nIndex < nLen);
vElement = SUBST(dpg_ProductList, 1, SCAN(':', dpg_ProductList) - 1) ;
vCount =SUBST(dpg_ProductList, SCAN(':', dpg_ProductList) + 1, LONG(dpg_ProductList)) ;
nIndex = nIndex +1 ;
END;
AsciiOutput('my.txt',vElement,vCount);