从Haskell中的String中剪切前x个字符

MKB*_* 06 1 string haskell

我正在尝试创建一个将列表中的部分字符串连接到另一个字符串的函数.我已经知道如何选择我想要的字符串,但现在我需要它们的第一部分(并且它并不总是相同的值).

所以我想剪掉一个字符串的第一部分

-- here is a function who should take a string and the numbers
-- of characters we want to take from the start
cutString :: Int -> String -> String
cutString x str = cut x str -- here's a way to take the first x characters
Run Code Online (Sandbox Code Playgroud)

以及使用它的方式:

print (cutString 3 "Hello World")
Output --> "Hel"
Run Code Online (Sandbox Code Playgroud)

有没有简单的方法可以做到这一点?

感谢您提供任何帮助或建议.

Cha*_*ert 5

见take:

take :: Int -> [a] -> [a]
Run Code Online (Sandbox Code Playgroud)

take n,应用于列表xs,返回xs长度的前缀n,或者xs自身ifn > length xs

在Prelude中使用它显示:

Prelude> take 3 "Hello"
"Hel"
Run Code Online (Sandbox Code Playgroud)