@Sixty Squares,
If your string was "Hello.~My Name is~<TEXT IN BRACKETS>~Man.", (each section is separated by ~) then the code is dead simple - here I split the string and look at each line in turn:
+ Code SnippetInputLine as string = "Hello.~My Name is~<TEXT IN BRACKETS>~Man."
split string InputLine, "~"
for Field = 1 to split count()
print "Looking at field "; Field; " - ";
if left$( get split word$(Field), 1 ) = "<" and right$( get split word$(Field), 1 ) = ">"
print "It's an enclosed string - contents are "; trim$( get split word$(Field), "<>")
else
print "It's a normal string - value is "; get split word$(Field)
endif
next
If the string you posted originally is actually what you want, then you need to work a little harder at the code:
+ Code SnippetInputLine as string = "Hello.~My Name is <TEXT IN BRACKETS> Man."
Field = 0
repeat
inc Field
Extract$ = GetField(InputLine, Field)
if Extract$ <> ""
print "Field "; Field; " - ";
if left$(Extract$, 1) = "<"
print "It's an enclosed string - contents are "; trim$( Extract$, "<>")
else
print "It's a normal string - value is "; Extract$
endif
endif
until Extract$ = ""
print ""
print "Done"
wait key
end
function GetField(InputLine as string, WantedField as integer)
local Field
local SearchPos
local EndPos
local DL$
DL$ = "~"
Field = 0
EndPos = 0
repeat
inc Field
SearchPos = EndPos + 1
EndPos = FindNextDelimiter( InputLine, "~<>", SearchPos )
if EndPos = 0 then EndPos = len(InputLine)+1
until Field = WantedField or EndPos > len(InputLine)
if Field = WantedField
select mid$(InputLine, EndPos)
case "<"
` This delimiter is part of the next field
dec EndPos
endcase
case ">"
` This delimiter is part of the current field, so don't adjust endpos
` Check character prior to field to see if it should be included
if SearchPos > 1
if mid$(InputLine, SearchPos - 1) = "<" then dec SearchPos
endif
endcase
case "~"
dec EndPos
endcase
endselect
exitfunction mid$( InputLine, SearchPos, EndPos - SearchPos + 1 )
endif
endfunction ""
function FindNextDelimiter(InputString as string, Delimiters as string, StartPos as integer)
local Pos
local Found
local i
Pos = len(InputString) + 9999
for i = 1 to len( Delimiters )
Found = instr( InputString, mid$(Delimiters, i), StartPos )
if Found > 0 then Pos = min(Pos, Found)
next
if Pos > len(InputString) then Pos = 0
endfunction Pos
This last one is a bit of a mess really. Anyway, it's given me one or two more ideas for new string functions to make this kind of parsing easier - thanks