using System; using System.Collections.Generic; using System.Text; namespace Pegasus { /// <summary> /// Has additional string methods. /// </summary> public static class StringHelper { /// <summary> /// Centers the specified string. /// </summary> /// <param name="str">The string to center.</param> /// <param name="ch">The char to pad on eather side.</param> /// <param name="length">The length.</param> /// <returns></returns> public static string Center( string str, char ch, int length ) { string result = str; int strLength = str.Length; if( strLength < length ) { int diff = length - strLength; result = result.PadLeft( ( diff / 2 ) + strLength, ch ); result = result.PadRight( diff + strLength, ch ); } return result; } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)