[futurebasic] Re: [FB] Parsing

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2004 : Group Archive : Group : All Groups

From: Bernie Wylde <bernie.w@...>
Date: Sun, 8 Aug 2004 13:31:00 +0100
On 8 Aug 2004, at 2:38, tedd wrote:

> Hi gang:
> Before I launch myself into doing something that everyone has already 
> done, I thought I would check first.
> I need a way to parse out segments of a text container -- such as 
> deleting text starting at some delimiter string and ending at another 
> delimiter string. For example, if I had text which contained:
> aaaa aaaaa aaaaaa aaaaaa \++ aaaaaa bbbbbb ccccccc ddddddd eeeeeeee _/ 
> aaaaa aaaaaa aaaaa
> and then parse out everything between the "\++" and "_/" to leave:
> aaaa aaaaa aaaaaa aaaaaa  aaaaa aaaaaa aaaaa
> Anyone have a simple function to do that?

I was going to keep these offlist because they're not very elegant. 
But, what the hell !... I'll do anything for a cheap plug  :)


local mode
local fn RemoveBlockFromString$(s as Str255, s1 as Str255, s2 as Str255)
dim as short startPos, endPos
startPos = instr(1, s, s1)
long if startPos
endPos = instr(startPos + len(s1), s, s2)
if endPos then s = left$(s, startPos - 1) + mid$(s, endPos + len(s2))
end if
until (startPos == 0) or (endPos == 0)
end fn = s

local mode
local fn RemoveBlockFromContainer(@cPtr as ptr, s1 as Str255, s2 as 
dim as Handle cH
dim as long   startPos, endPos, size
cH = [cPtr]
size = fn GetHandleSize(cH)
startPos = fn munger(cH, 0, @s1[1], s1[0], _nil, _nil)
long if (startPos >= 0)
endPos = fn munger(cH, startPos + s1[0], @s2[1], s2[0], _nil, _nil)
long if (endPos >= 0)
endPos += s2[0]
BlockMove([cH] + endPos, [cH] + startPos, size - endPos)
size -= (endPos - startPos)
SetHandleSize(cH, size)
end if
end if
until (startPos < 0) or (endPos < 0)
end fn

dim as container gC
dim as Str255 s, s1, s2

window 1

s1 = "\++"
s2 = "_/"
s = "TWM (The Window Maker) is \++probably_/the best OS X FutureBasic 
GUI builder in the world"
gC = "\++Don't _/go here: 
print s
print gC
print fn RemoveBlockFromString$(s, s1, s2)
fn RemoveBlockFromContainer(gC, s1, s2)
print gC

until 0