Extension.String.cs 884 B

12345678910111213141516171819202122232425262728293031
  1. namespace TBL.CSharp.Base
  2. {
  3. public static partial class Extension
  4. {
  5. /// <summary>
  6. /// 将一个字符串重复 <paramref name="count"/> 次
  7. /// </summary>
  8. public static string Repeat(this string source, int count)
  9. {
  10. var result = string.Empty;
  11. for (var i = 0; i < count; i++)
  12. {
  13. result += source;
  14. }
  15. return result;
  16. }
  17. /// <summary>
  18. /// 切换首字母大小写
  19. /// </summary>
  20. public static unsafe string CaptionSwitch(this string str, bool isUpper)
  21. {
  22. if (str == null) return null;
  23. var ret = string.Copy(str);
  24. fixed (char* ptr = ret)
  25. *ptr = isUpper ? char.ToUpper(*ptr) : char.ToLower(*ptr);
  26. return ret;
  27. }
  28. }
  29. }