.net - 我无法从字符串中打印字符

标签 .net string f# char

我试过这个:

open System
let main() =
    let mutable str1 = "qwerty"
    printfn "%c" str1[0]
main()

明白了:

error FS0597: Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized

我找到了这个网站: https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/strings 在这里它工作我不知道为什么。我找到了其他网站,每个人都在谈论括号

open System
let main() =
    let mutable str1 = "qwerty"
    printfn "%c" (str1[0])
main()

得到这个:

error FS0003: This value is not a function and cannot be applied

最佳答案

如果您想打印字符串中的单个字符,您实际上需要在对象和方括号之间放置一个点。

printfn "%c" str1.[0]

MSFT docs: Access elements

微软在这里写道:

You can access array elements by using a dot operator (.) and brackets ([ and ]).

但是,他们的示例实际上也不包含。然而,为了访问数组元素,您需要使用点运算符。

关于.net - 我无法从字符串中打印字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69865866/

相关文章:

.net - AutoCAD .NET API - 中断关闭托盘/窗口/用户控制命令

c# - 在 Entity Framework 中按名称获取字段

f# - 类型没有 null 作为正确的值

parsing - 在F#中解析时如何处理错误

c# - 通用列表未插入到 MongoDB 中

c# - 使用静态方法生成随机数是一种好习惯吗?

点击事件上的Javascript不读取其他语句或变量

string - Bash 循环字符串并向其添加字符串

c++ - 为什么 strlen 对我不起作用?

f# - 在 Mono 下 fsharp 编译失败并出现 NuGet 错误