December 04, 2020, 10:32:53 AM

Author Topic: [bb] Text extractor by TAS [ 1+ years ago ]  (Read 571 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Text extractor by TAS [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Text extractor
Author : TAS
Posted : 1+ years ago

Description : Use this code to extract all the text enclosed in quotes from a series of  bb files to a single text file so it can be spelled checked.

Code :
Code: BlitzBasic
  1. ;Use this code to extract all the text enclosed in quotes from a series of
  2. ;bb files to a single text file so it can be spelled checked.
  3.  
  4. ;create output file
  5. f2=WriteFile("Game text.txt")
  6. If f2=0 Then End                ;abort on fail
  7.  
  8. Repeat
  9.         fn$=RequestFile("Select File for processing","bb")
  10.         If Len(fn)=0 Then Exit ;Done
  11.        
  12.         f=ReadFile(fn) 
  13.         If f=0 Then Exit ;done
  14.         r$=";********** "+fn+Chr(13)    ;save for first line of output file
  15.         WriteLine f2,r$ ;title line
  16.         n=0
  17.         While Not Eof(f)
  18.                 n=n+1   ;line number
  19.                 s$=ReadLine(f)                  ;read next line of text
  20.                 k=Instr(s,Chr(34))      ;check for quote mark
  21.                
  22.                 ;if quote mark found process line to close quote
  23.                 While k>0
  24.                         j=Instr(s,Chr(34),k+1)  ;find next quote mark right of quote at position k
  25.                         If j=0 Then j=Len(s)            ;if none take remaining line as quote
  26.                         Print Str(n)+Chr(9)+Mid(s,k+1,j-k-1)    ;output line # and text within quotes to screen
  27.                         WriteLine f2,Str(n)+Chr(9)+Mid(s,k+1,j-k-1)+Chr(13)     ;to file
  28.                         If j=Len(s) Then s="" Else s=Right(s,Len(s)-j-1)                ;strip text up to second quote from string
  29.                         k=Instr(s,Chr(34))      ;check for a 3rd, 5th, ... quote mark in string
  30.                 Wend                   
  31.         Wend
  32.         CloseFile(f)
  33.         m=m+n
  34. Forever
  35.  
  36. CloseFile(f2)
  37. Notify "Lines checked "+m
  38. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal