Example #1
0
        /// <summary>
        /// In a given block adds a specific number of a given character for indentation at the beginning of each line.
        /// </summary>
        /// <param name="source">The given block.</param>
        /// <param name="total">The total number of the given character to add for indentation.</param>
        /// <param name="indentationCharacter">The given character to use for indentation.</param>
        /// <returns>The given block with the number of a given character for indentation at the beginning of each line. If the number of the given character is equal to or less than 0 (zero) it will return the original string.</returns>
        public static string IndentBlock(this string source, int total, IndentationCharacter indentationCharacter)
        {
            if (total <= 0)
            {
                return(source);
            }

            source = source ?? string.Empty;
            var sb           = new StringBuilder();
            var indentations = new string(Convert.ToChar(indentationCharacter.GetStringValue()), total);
            var lines        = source.Split(new string[] { StringConstants.CRLF }, StringSplitOptions.None);

            foreach (var line in lines)
            {
                if (line.IsNullOrEmpty())
                {
                    sb.AppendLine(line);
                }
                else
                {
                    sb.Append(indentations).AppendLine(line);
                }
            }

            return(sb.ToString());
        }
Example #2
0
        /// <summary>
        /// In a given string adds a specific number of a given character for indentation at the beginning.
        /// </summary>
        /// <param name="source">The given string.</param>
        /// <param name="total">The total characters to add for indentation.</param>
        /// <param name="indentationCharacter">The given character to add.</param>
        /// <returns>The given string with the number of a given character for indentation at the beginning. If the number of characters is equal to or less than 0 (zero) it will return the original string.</returns>
        public static string Indent(this string source, int total, IndentationCharacter indentationCharacter)
        {
            if (total <= 0)
            {
                return(source);
            }

            var indentations = new string(Convert.ToChar(indentationCharacter.GetStringValue()), total);

            return(indentations + (source ?? string.Empty));
        }