;here is a string with a " in it.infile = ReadFile("test.bb")While(Not(Eof(infile))) val$ = ReadLine(infile) If(Instr(val$,Chr$(34),1)>0) Then RuntimeError "found it!" EndIf Wend CloseFile infile
l$ = "This is a "+Chr(34)+"quote"+Chr(34)Print l$Print Instr(l$,Chr$(34))
PL$= ReadLine(FH1):Print PL$:Print Len(PL$);Print Asc(Mid$(PL$,Instr(PL$,",")-1))RL$=PL$While Instr(RL$,",") TC=Instr(RL$,",") If TC.CK If Asc(Mid$(RL$,TC-1,1))<>34 TC=TC+Instr(Mid$(RL$,TC+1),","):Goto CK ElseIf Asc(Mid$(RL$,TC-1,1))=34 Print Mid$(RL$,2,Len(RL$)-1) EndIf SD=SD+1 If SD>=2 Print TC:Print Mid$(RL$,2,TC-1):HALT(1) EndIf RL$=Mid$(RL$,TC+1) EndIf; E=E+1Wend
If you were to look up 'lexical analyzer' ( don't worry about the name - it just looks all technical and sci-fi but its not really ) you could create a powerful parser that can parse practically anything you want.
"07076051.wav","Two-stroke petrol engine driving small elevator, start, run, stop.","194","Engines: Petrol","EC117D","Diesel & Petrol Engines","4"
Const TOKEN_UNKNOWN = 0Const TOKEN_STRING = 1Const TOKEN_COMMA = 2Const TOKEN_EOL = 3Const TOKEN_EOF = 4Type TToken Field value$ Field tipeEnd TypeType TLexer Field in$ Field inlength Field token_start Field token_endEnd TypeFunction TokenTypeToString$(TokenType) Select TokenType Case TOKEN_UNKNOWN Return "TOKEN_UNKNOWN" Case TOKEN_STRING Return "TOKEN_STRING " Case TOKEN_COMMA Return "TOKEN_COMMA " Case TOKEN_EOL Return "TOKEN_EOL " Case TOKEN_EOF Return "TOKEN_EOF " End SelectEnd FunctionFunction Lexer_NextToken.TToken(lex.TLexer) ; default to an unknown token Local t.TToken = New TToken t\tipe = TOKEN_UNKNOWN ; reset the token start position lex\token_start = lex\token_end ; end of line? If Lexer_IsEndOfLine(lex) ; could deal with end-of-file also if wanted t\tipe = TOKEN_EOL t\value = "end-of-line" ; is a '~q' - change as required Else If Lexer_IsQuote(lex) While lex\token_end <= lex\inlength lex\token_end = lex\token_end + 1 If Lexer_IsQuote(lex) Exit Wend t\tipe = TOKEN_STRING t\value = Mid(lex\in, lex\token_start, lex\token_end - lex\token_start) Else ; make a known symbol If Asc(Mid(lex\in, lex\token_end, 1)) = 44 ; ',' t\tipe = TOKEN_COMMA t\value = "," lex\token_end = lex\token_end + 1 EndIf EndIf Return tEnd FunctionFunction Lexer_IsQuote(lex.TLexer) ; change this code to suit detecting a " character instead of ~q If Mid(lex\in, lex\token_end, 1) = Chr(34) lex\token_end = lex\token_end + 1 Return True EndIfEnd FunctionFunction Lexer_IsEndOfLine(lex.TLexer) Return lex\token_end >= lex\inlengthEnd Function; you would now create a TParser to handle the token types as per the syntax that you expectType TParser Field lexer.TLexer Field token.TTokenEnd TypeFunction Parser_Parse(parser.TParser) Parser_NextToken(parser) While parser\token\tipe <> TOKEN_EOL ; Select the parser\token\tipe and do something meaningful with it, here the code prints out the token data ; You would do something more meaningful with the data Print TokenTypeToString(parser\token\tipe) + " : " + parser\token\value Parser_NextToken(parser) WendEnd FunctionFunction Parser_NextToken(parser.TParser) parser\token = Lexer_NextToken(parser\lexer)End FunctionLocal in$ = Chr(34) + "07076051.wav" + Chr(34) + ","in = in + Chr(34) + "Two-stroke petrol engine driving small elevator, start, run, stop." + Chr(34) + ","in = in + Chr(34) + "194" + Chr(34) + ","in = in + Chr(34) + "Engines: Petrol" + Chr(34) + ","in = in + Chr(34) + "EC117D" + Chr(34) + ","in = in + Chr(34) + "Diesel & Petrol Engines" + Chr(34) + ","in = in + Chr(34) + "4"+Chr(34); set up a lexer with dataLocal lexer.TLexer = New TLexerlexer\token_start = 1lexer\token_end = 1lexer\in = in ; "~q07076051.wav~q,~qTwo-stroke petrol engine driving small elevator, start, run, Stop.~q,~q194~q,~qEngines: Petrol~q,~qEC117D~q,~qDiesel & Petrol Engines~q,~q4~q"lexer\inlength = Len(lexer\in); setup a parser with the lexerLocal parser.TParser = New TParserparser\lexer = lexer; use the parser to control the lexer and parse the output of the lexer tokensParser_Parse(parser)