[futurebasic] Re: [FB] FB string parsing

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2012 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Mon, 2 Apr 2012 15:47:17 -0700
On Apr 2, 2012, at 3:10 PM, Spencer Ted wrote:




> A frame which is to be extracted and parsed would start with the "p" and end with the last character before the next "p".
You might not be comfortable in CoreFoundation yet but CFStringCreateArrayBySeparatingStrings() could be used to find "p" and create an array. This call can operate on a very large string and isn’t limited to the pascal length of 255. There have been posted examples but another one could be posted if interested.




> Consider this, being called every 2 ticks:

I didn’t study the code but here is a thought ( FWIW ). First debug the string parsing to get it right. Use PRINTs to display what is in the string at each point of the processing. Then revisit the logic to make sure the magic number ( 16 ) really works in all cases. The below is an example of putting in PRINTs( I used the ConsoleWindow to make the output more readable ) HTH:

'--------------
include "ConsoleWindow"

Begin globals
dim as str255 gC1
end globals

local fn showvoltage
dim as str255 c
dim as short nCharsReady,pPos, volt

//nCharsReady = lof (-1)
//read #-1,c;nCharsReady
//gc1 = gc1 + c

gc1 = "p1234r2345s0123p1235r2346s0125p"
long if len( gc1 )	// only if stuff built up
gc1 = right$(gC1,16)		// chuck most of it, but leave a p behind
print "right$(gC1,16 ) = ";gc1
pPos = instr(1,gC1,"p")
print "pPos = ";pPos
gC1 = mid$(gC1,pPos)	// get the p and everything that follows
print "mid$(gC1,pPos) = ";gC1
end if

pPos = instr(2,gc1,"p")	// is there a next "p"?

long if pPos	// yup
Edit field 1,gc1
c = left$(gC1,pPos-1)
gC1 = right$(gC1,len(gC1)-pPos)	//take out what we've read
edit field 3,c
edit field 4,str$(nCharsReady)
pPos = instr(1,c,"r")
volt = val(left$(c,pPos-1))
appearance button 2,,volt	// updte the voltage slider
end if

end fn

fn showvoltage
RunApplicationEventLoop
'--------------



Brian S.