Another way would be to use the binary input mode. Example
dim a$(500) 'or whatever
open "sometext.txt" for binary as #1
i = 0
do until eof(1)
m$ = ""
do
REM * Get a single byte from the input file
get$ #1,1,t$
REM * At the end of the input file. Exit loop
if eof(1) then exit loop
REM * Exit loop on spaces, C/R or L/F
if t$ = chr$(32) or t$ = chr$(13) or t$ = chr$(10) then exit loop
REM * Concan the temporary string
m$ = m$ + t$
loop
REM * The temporary string MAY wind up being NULL. Ignore.
if m$ <> "" then
incr i
a$(i) = m$
end if
loop
close #1
------------------
Announcement
Collapse
No announcement yet.
String Manipulation Help
Collapse
X
-
Hi,
I think the best way is:
1) read in one line with line input command
e.g. line input test%,liniein$
linein$="This is then ..."
2) look for the first " "=space with the instr command
3) read the 1. word in with
4) look for then second " "=space see 2) and so on
5) till posspace% is 0
5.5) read in the last word
6) read in the next linein$... till end
one example:
cls
a$="das ist ein Test"
poss%=1
do
incr poss%,le% 'set the search pos
'?" - ",poss%
pos1%=instr(poss%,a$," ") 'search for " "
'?pos1%,poss%
if pos1%=0 then 'no more spaces
'read in the last word there is no space after !
?mid$(a$,poss%,(len(a$)-poss%+1))
exit loop
end if
'the first words
?mid$(a$,poss%,(pos1%-poss%))
le%=pos1%-poss%+1 'len of the word
loop
hope this helps
Regards
Matthias Kuhn
------------------
Leave a comment:
-
-
String Manipulation Help
What is the easiest way to read and assign each individual word of an ascii text file (with line breaks) as an element of a string array?
ie: FILE.TXT
NOW IS
THE TIME FOR
ALL GOOD MEN…
becomes:
s$(1)="NOW"
s$(2)="IS"
s$(3)="THE"
S$(4)="TIME"
…
Thank you in advance.
-jay
Tags: None
-
Leave a comment: