Parsing strings into numbers

I often need to take some string input and convert it to a number. This should be reasonably extensible:

function parseString2Num(inString)
	string inString
	
	string trueFalseList = "false;true;"
	string yesNoList = "no;yes;"
	string dayList = ";mon;tue;wed;thu;fri;sat;sun;"
	string fullDayList = ";monday;tuesday;wednesday;thursday;friday;saturday;sunday"
	string monthList = ";jan;feb;mar;apr;may;jun;jul;aug;sep;oct;nov;dec;"
	string fullMonthList = ";january;february;march;april;may;june;july;august;september;october;november;december;"
	
	make/t/o TEMPLISTWAVE = {trueFalseList,yesNoList,dayList,fullDayList,monthList,fullMonthList}
	
	variable i
	variable which = -1
	
	for(i=0;i<dimSize(tempListWave,0) && which < 0; i+=1)
		which = whichListItem(inString, tempListWave[i],";",0,0)
	endFor
	
	killwaves/z TEMPListWave
	
	return(which)
end

Forum

Support

Gallery

Igor Pro 10

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More