In F# you can create a list from 1 to 10 using the range operator, but is it possible to use letters from the alphabet to do the same? I have been searching for a while and trying a few different things but with no success, and I don't want to have to type the alphabet in the program manually.
在F#中,您可以使用范围运算符创建1到10的列表,但是可以使用字母表中的字母来执行相同的操作吗?我一直在寻找一些不同的东西,但没有成功,我不想手动在程序中键入字母表。
I'm looking for something along the lines of:
我正在寻找以下内容:
let list = [ "a" .. "z" ]
I know I would have to use regex somehow but I can't find a lot of information on it and it seems to be called something different in F#.
我知道我必须以某种方式使用正则表达式,但我找不到很多关于它的信息,它似乎在F#中被称为不同的东西。
1 个解决方案
#1
9
You just need to use single quotes to specify characters rather than strings:
您只需要使用单引号来指定字符而不是字符串:
let list = [ 'a' .. 'z' ]
// yields: [a; b; c; ... ]
#1
9
You just need to use single quotes to specify characters rather than strings:
您只需要使用单引号来指定字符而不是字符串:
let list = [ 'a' .. 'z' ]
// yields: [a; b; c; ... ]