Thursday, January 5, 2012

Fill String With Characters

There is a nice little trick, with which a string can quickly be filled with arbitrary characters.
The class string provides therefor the following constructor:
new string(meinzeichen, anzahl).
With this a new string is created, containing anzahl many characters with the value meinzeichen.
The following example creates a string consisting of 30 "-":

string filled = new string('-', 30);

No comments:

Post a Comment