简体   繁体   English

如果我有重复的次数,如何重复一个字符组成一个字符串?

[英]How can I repeat a character to make up a string if I have a number for the times to repeat?

I have this code: 我有以下代码:

vm.Points = phrase.Points.ToString();

I would like to replace it with something that would put an X character as many times as there are phrase.Points where phrase.Points is an integer. 我想用一个放置X字符的次数替换它,该次数要是存在短语.Points的次数,而短语.Points是整数。

So if phrase.Points has a value of 5 then I would like the value of vm.Points to be "XXXXX" 因此,如果phrase.Points的值为5,那么我希望vm.Points的值为“ XXXXX”

您正在寻找这个:

new String('X', phrase.Points);

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

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