如何用所需字符填充字符串

发布于 2024-10-09 03:09:21 字数 71 浏览 0 评论 0原文

我需要获取带有 8 个“*”符号的字符串。我如何在 .NET 3.5 中做到这一点? .NET 4.0?

谢谢。

I need to get string with 8 '*' symbols. How can I do that in .NET 3.5? .NET 4.0?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

念﹏祤嫣 2024-10-16 03:09:21

尝试:

string str = new string('*', 8);

Try:

string str = new string('*', 8);
陌上芳菲 2024-10-16 03:09:21

我自己的快速解决方法:

"".PadLeft(Password.Length,'*')

:)

但我想这应该是更好的解决方案。

谢谢。

My own quick workaround:

"".PadLeft(Password.Length,'*')

:)

But I guess it should be better solution.

Thanks.

没有伤那来痛 2024-10-16 03:09:21

这对我有用:

private static string WelcomeString = "wordsandstuff";
private static Int32 padInt = WelcomeString.Length;
public static void Main(string[] args)
{
  Console.WriteLine(WelcomeString);
  Console.WriteLine("".PadLeft(padInt, '='));
  Console.ReadKey();
}

This worked for me:

private static string WelcomeString = "wordsandstuff";
private static Int32 padInt = WelcomeString.Length;
public static void Main(string[] args)
{
  Console.WriteLine(WelcomeString);
  Console.WriteLine("".PadLeft(padInt, '='));
  Console.ReadKey();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文