重复一个字符X次? [英] Repeating a character X number of times?

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

问题描述

我用什么功能重复一次X字符?例如,

说我要创建一个包含40个破折号的字符串。


提前谢谢

-

David Veeneman

远见系统

解决方案

大卫你好,


string dash ="" ;;

for(int i = 0; i< 40; i ++)

{

dash + ="''" ;;

}


DV>我用什么函数重复一次X字符?对于

DV>例如,假设我要创建一个包含40个破折号的字符串。

DV>

DV>提前致谢

DV>

---

WBR,

Michael Nemtsev ::博客: http://spaces.msn.com/laflour


有时一个人仍忠于某一事业,只因为它的反对者不会因为b $ b不再是平淡无奇的。 (c)Friedrich Nietzsche


有一个String构造函数重载,允许你这样做。
http://msdn2.microsoft.com/en-us/xsa4321w.aspx


-

Tim Wilson

..NET Compact Framework MVP


" David Veeneman" < da **** @ nospam.com(域名是我的姓氏)>写在

消息新闻:Oc ************** @ TK2MSFTNGP02.phx.gbl ...

我使用什么功能重复一个字符X次?例如,说我要创建一个包含40个破折号的字符串。

提前致谢
-
David Veeneman
远见系统


当然,你意识到这个方法实际上创建了40个不同的
字符串对象不是吗?由于字符串是不可变的,因此无论何时
为现有字符串赋值或附加到现有字符串,都会创建一个

新字符串,其大小和放置内容




最好使用Tim建议的相应字符串构造函数。


What function do I use to repeat a character X number of times? For example,
say I want to create a string with 40 dashes.

Thanks in advance
--
David Veeneman
Foresight Systems

解决方案

Hello David,

string dash = "";
for (int i = 0; i < 40; i++)
{
dash += "''";
}

DV> What function do I use to repeat a character X number of times? For
DV> example, say I want to create a string with 40 dashes.
DV>
DV> Thanks in advance
DV>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


There''s a String constructor overload that will allow you to do this.
http://msdn2.microsoft.com/en-us/xsa4321w.aspx

--
Tim Wilson
..NET Compact Framework MVP

"David Veeneman" <da****@nospam.com (domain is my last name)> wrote in
message news:Oc**************@TK2MSFTNGP02.phx.gbl...

What function do I use to repeat a character X number of times? For
example, say I want to create a string with 40 dashes.

Thanks in advance
--
David Veeneman
Foresight Systems



You realize, of course, that this method actually creates 40 different
strings objects don''t you? Since strings are immutable, whenever you
assign a value to an existing string or append to an existing string, a
new string is created of the appropriate size and the contents placed
in it.

Better to use the appropriate string constructor as Tim suggested.


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

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