如何重复一组字符 [英] How to repeat a set of characters

查看:84
本文介绍了如何重复一组字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想多次重复一组字符。我知道如何使用单个字符:

I'd like to repeat a set of characters multiple times. I know how to do it with a single character:

string line = new string('x', 10);

但是我想要的是这样的东西:

But what I'd like would be something more like this:

string line = new string("-.", 10);

这将导致:-.-.-.-.-.-.- .. -.-。

which would result in: -.-.-.-.-.-.-.-.-.-.

我知道字符串构造函数无法做到这一点,但是BCL中还有其他方法吗?

I know the string constructor can't do it, but is there some other way within the BCL? Other suggestions?

谢谢!

推荐答案

通过 Bala R

var s = String.Concat(Enumerable.Repeat("-.", 10));

这篇关于如何重复一组字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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