如何在Haskell中打印相同的字符n次 [英] How to print the same char n times in Haskell

查看:78
本文介绍了如何在Haskell中打印相同的字符n次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印一个在字符串下划线n次的字符,在Haskell中字符串的长度为n.

I would like to print a char underlining a String n times, with n the length of the String in Haskell.

我应该怎么做?

我的字符串是:可用字符(x)"并且我想在该句子下划线加一个char,该句子的长度应与"Available Chars(x)"完全相同.但是x是一个整数,因此它可以是"1"或"10"或"1000"等.因此长度是可变的.我有长度,但是只要字符串是...,我都不知道如何打印该字符...

My String is: "Available Chars (x)" and I want to have a char underlining that sentence, which should have exactly the same length as the "Available Chars (x)". But x is an int, so it could be "1" or "10" or "1000" etc.. so the length is variable. I got the length but i didnt know how to print that char as long as the string is...

推荐答案

使用这将为您提供一个字符串,该字符串是字符-"的n倍,其中n是输入字符串的长度.等同于:

This will give you a string which is n times the character '-' where n is the length of the input string. It is the same as:

underline = map (const '-')

然后,您可以像这样使用它(例如,如果 yourString ="Available Chars(111)" ):

You can then use it like this (if for example yourString = "Available Chars (111)"):

> putStrLn yourString >> putStrLn (underline yourString)
Available Chars (111)
---------------------

这篇关于如何在Haskell中打印相同的字符n次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆