简体   繁体   English

如何在CLEAN中小写字符串

[英]How to lowercase a string in CLEAN

I have a problem in CLEAN, how can I make lowercase all letter in a string? 我在CLEAN中遇到问题,如何在字符串中将所有字母都小写? I can do it through an char array, but i need to do it with a string too. 我可以通过一个char数组来完成它,但是我也需要使用字符串来完成它。 I have the code below so far: 到目前为止,我的代码如下:

module Something

import StdEnv, StdLib

arrayLower:: [Char] -> [Char]
arrayLower[x:xs] = (map toLower [x:xs]) 


stringLower:: String -> String
stringLower_ = ""
stringLowers = toString (arrayLower s)

Start:: String     
Start = stringLower"SSSsss"

Your first case 你的第一种情况

stringLower _ = ""

means that stringLower applied to anything is the empty string. 表示应用于所有内容的stringLower为空字符串。
I'm surprised that you didn't get a warning for the redundant second case. 我很惊讶您没有收到多余的第二种情况的警告。

A String is an array (unboxed, so it's a {#Char} ), and you say that you already know how to do this with arrays, but your arrayLower is defined for lists of Char ( [Char] ), not arrays. String 一个数组(未装箱,因此为{#Char} ),您说您已经知道如何使用数组,但是您的arrayLower是为Char[Char] )列表而不是数组定义的。

This, using an array comprehension, works for me: 使用数组理解,这对我有用:

stringLower :: String -> String
stringLower s = {toLower c \\ c <-: s} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM