Extensions/StringExtensions.cs
(开头部分) 28KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ComLib.Extensions
{
/// <summary>
/// This static class contains several common String extension methods.
/// </summary>
public static class StringExtensions
{
#region Appending
/// <summary>
/// Multiply a string N number of times.
/// </summary>
/// <param name="str">String to multiply.</param>
/// <param name="times">Number of times to multiply the string.</param>
/// <returns>Original string multiplied N times.</returns>
public static string Times(this string str, int times)
{
if (string.IsNullOrEmpty(str)) return string.Empty;
if (times <= 1) return str;
string strfinal = string.Empty;
for (int ndx = 0; ndx < times; ndx++)
strfinal += str;
return strfinal;
}
/// <summary>
/// Increases the string to the maximum length specified.
/// If the string is already greater than maxlength, it is truncated if the flag truncate is true.
/// </summary>
/// <param name="str">The STR.</param>
/// <param name="maxLength">Length of the max.</param>
/// <param name="truncate">if set to <c>true</c> [truncate].</param>
/// <returns>Increased string.</returns>
public static string IncreaseTo(this string str, int maxLength, bool truncate)
{
if (string.IsNullOrEmpty(str)) return str;
if (str.Length == maxLength) return str;
if (str.Length > maxLength && truncate) return str.Truncate(maxLength);
string original = str;
while (str.Length < maxLength)
{
// Still less after appending by original string.
if (str.Length + original.Length < maxLength)
{
str += original;
}
else // Append partial.
{
str += str.Substring(0, maxLength - str.Length);
后面还有 710 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
