问题描述
我试图从SML文件中读取文本。最后,我想要一个单独的单词列表;然而,我在如何在 TextIO.elem 只是 char 的同义词,因此您可以使用 str 函数将其转换为字符串。但是,正如我在其他地方所回答的,我建议使用 TextIO.inputAll 来立即获取字符串。
一个函数,需要一个instream并提供所有(剩余)的单词:
val words = String.tokens Char.isSpace o TextIO.inputAll
这个函数的类型是 TextIO.instream - >字符串列表。
I'm trying to read text from a file in SML. Eventually, I want a list of individual words; however, I'm struggling at how to convert between a TextIO.elem to a string. For example, if I write the following code it returns a TextIO.elem but I don't know how to convert it to a string so that I can concat it with another string
TextIO.input1 inStream
TextIO.elem is just a synonym for char, so you can use the str function to convert it to a string. But as I replied to elsewhere, I suggest using TextIO.inputAll to get a string right away.
Here is a function that takes an instream and delivers all (remaining) words in it:
val words = String.tokens Char.isSpace o TextIO.inputAll
The type of this function is TextIO.instream -> string list.
这篇关于如何从TextIO中以sml / ml获取字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!