Is there a "Space(n)" method in C#/.Net? -
i'm converting ancient vb6 program c# (.net 4.0) , in 1 routine lots of string manipulation , generation. of native vb6 code uses have analogues in c# string class, e.g., trim(). can't seem find replacement space(n), apparently generates string n spaces.
looking through msdn documentation, there seems space() method vb.net couldn't find mentioned outside of vb.net context. why this? thought .net languages share same clr.
does c# or .net have generic space() method can use in c# i'm overlooking somewhere?
n.b. i'm aware writing one-liners generate n-spaces popular quiz-question , programmers' bar-game programming languages, i'm not looking advice on that. if there's no native way in c#/.net it's easy enough write simple method; don't want reinvent wheel.
use constructor on system.string
:
new string(' ', 10);
http://msdn.microsoft.com/en-us/library/xsa4321w(v=vs.110).aspx
here's neat extension method can use, (although it's better use string
constructor , save method call):
public static class charextensions { public static string repeat(this char c, int count) { return new string(c, count); } } ... string spaces = ' '.repeat(10);
Comments
Post a Comment