在 Racket 中将字符串变成数字 [英] Turn string into number in Racket

查看:23
本文介绍了在 Racket 中将字符串变成数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 read 从文件中获取一行.文档说 read 返回 any,那么它是否将行转换为字符串?我在将字符串 "1" 转换为数字 1 或将 "500.8232" 转换为 500.8232 时遇到问题.我也想知道 Racket 是否可以直接从文件中读取数字.

I used read to get a line from a file. The documentation said read returns any, so is it turning the line to a string? I have problems turning the string "1" to the number 1, or "500.8232" into 500.8232. I am also wondering if Racket can directly read numbers in from a file.

推荐答案

查看他们的文档搜索,它是完整和准确的.转换函数通常具有 foo->bar 的形式(您可以假设它接受一个 foo 并返回一个由它构造的 bar).

Check out their documentation search, it's complete and accurate. Conversion functions usually have the form of foo->bar (which you can assume takes a foo and returns a bar constructed from it).

您听起来像是在寻找一个函数,它接受一个 string 并返回一个 number,而实际上,string->number 确实存在,并且几乎完全符合您的要求.

You sound like you're looking for a function that takes a string and returns a number, and as it happens, string->number does exist, and does pretty much exactly what you're looking for.

这篇关于在 Racket 中将字符串变成数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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