0

我试图在 10 行中引入一个包含 10 个单词(不带逗号)的简单列表,并将它们保存为 Small Basic 中的列表或数组。

我知道我需要遍历文件中的所有行,但我只能用单个字母来完成它。

到目前为止我已经做到了

OpenFile = File.ReadContents("example.txt")
For i = 1 To Text.GetLength(OpenFile)
    WordList[i] = Text.GetSubText(OpenFile, i, 5)
EndFor
TextWindow.Write(WordList)

我没有比这更进一步的了,不知道从这里去哪里。

4

2 回答 2

0

我知道我可能已经太晚了,但万一你还在继续(是的,我会假设你没有参加计算机科学的 AQA GCSE,而是喜欢在 Small Basic 中编写代码以获得乐趣) ,但是您应该考虑使用此代码,因为这样效率更高。

fpath = "\\Downloads\file.txt"

For i = 1 To 10
  line[i] = File.ReadLine(fpath, i) 
EndFor

For i = 1 To 10
  TextWindow.WriteLine("Line " + i + " contains: " + line[i])
EndFor

(您需要将 fpath 变量更改为您的文件所在的位置)。然后,这也会打印出数组以进行检查,但对于您的任务,您需要摆脱它。

于 2016-01-28T18:38:24.440 回答
0

您可以使用 readline 来获取一行中的所有字符/单词/句子,这是一个示例,它不完整,但它给出了您需要什么的想法,

'SAVE THE PROGRAM FIRST!!!!! 
'DO NOT RUN UNTIL YOU DO THAT.
makesaves()
getsaves()
printsaves()
Sub makesaves ' where you make saves. its reusable. 
PATH = Program.Directory + "\animals\" ' SAVE THIS IN A FOLDER YOU WILL FIND IN 
'ELSE IT WILL SAVE IN A DUMP FOLDER WHICH IS NEARLY IMPOSSIBLE TO FIND
NAME = "Animal"
EXT = ".txt"

filesave["1"] = "Cheetah"
filesave[2] = "horse"
filesave[3] = "dog"
filesave[4] = "cat"
filesave[5] = "mouse"
filesave[6] = "turtle" 
filesave[7] ="Bird"
filesave[8] = "snake"
filesave[9] = "snail"
filesave[10] = "Rat"
'makes the saves
File.CreateDirectory(PATH) ' makes the path.
File.WriteContents(PATH+NAME+EXT, filesave)

filesave = "" ' cleans the file so you dont get repeats. e.i. - save dog.    read dog, save dog, read dog dog.
'this makes it so you see dog once. its an override.
 filesave = File.ReadContents(PATH + NAME + EXT)  'reads the content 

endsub

Sub getsaves
filesave = File.ReadContents(PATH+NAME+EXT) ' how this writes is cheetah;   horse; 

cheetah = filesave[1]
horse = filesave[2]
dog = filesave[3] 
cat = filesave[4]
mouse = filesave[5] 'mouse and turtle as different color because they can be   used as functions. ignore
turtle = filesave[6]  
bird = filesave[7]
 snake = filesave[8]
 snail = filesave[9] 
 rat = filesave[10] 


EndSub
Sub printsaves
i = 1
While i < 11 
  TextWindow.WriteLine(filesave[i])
i = i+1
endwhile


endsub
于 2016-01-11T15:31:03.760 回答