[英]F# I can't print char from string
I tried this:我试过这个:
open System
let main() =
let mutable str1 = "qwerty"
printfn "%c" str1[0]
main()
got this:明白啦:
error FS0597: Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized
错误 FS0597:连续的参数应该用空格或元组分隔,并且涉及函数或方法应用程序的参数应该用括号括起来
I found this site: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/strings and here it's working I don't know why.我找到了这个网站: https : //docs.microsoft.com/en-us/dotnet/fsharp/language-reference/strings在这里我不知道为什么。 I found other sites, where everyone said about parentheses
我找到了其他网站,每个人都说括号
open System
let main() =
let mutable str1 = "qwerty"
printfn "%c" (str1[0])
main()
and got this:得到了这个:
error FS0003: This value is not a function and cannot be applied
错误 FS0003:此值不是函数,无法应用
If you want to print a single character from a string you actually need to put a dot in between the object and the squared brackets.如果您想从字符串中打印单个字符,您实际上需要在对象和方括号之间放一个点。
printfn "%c" str1.[0]
MSFT docs: Access elements MSFT 文档:访问元素
Here writes Microsoft: "You can access array elements by using a dot operator (.) and brackets ([ and ])."微软在这里写道:“您可以使用点运算符 (.) 和括号([ 和 ])访问数组元素。” However, their example actually also does not include the
dot
.然而,他们的例子实际上也不包括
dot
。 Nevertheless, in order to access array elements, you need to use the dot operator.然而,为了访问数组元素,您需要使用点运算符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.