如何从TextIO中以sml / ml获取字符串? [英] How to get a string from TextIO in sml/ml?

查看:108
本文介绍了如何从TextIO中以sml / ml获取字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从SML文件中读取文本。最后,我想要一个单独的单词列表;然而,我在如何在 TextIO.elem 字符串之间进行转换。例如,如果我编写下面的代码,它会返回一个 TextIO.elem ,但我不知道如何将其转换为字符串,以便可以将它与另一个字符串



TextIO.input1 inStream

解决方案 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获取字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆