diff --git a/Base/Lib/Helpers.cs b/Base/Lib/Helpers.cs index f56341c..7266cb5 100644 --- a/Base/Lib/Helpers.cs +++ b/Base/Lib/Helpers.cs @@ -601,4 +601,34 @@ public static class Helpers return false; } + /// + /// 문자열을 지정된 최대 자리수만큼 자르고 초과하면 "..."을 추가. + /// + /// 문자열 + /// 최대 자리수 + /// 잘린 문자열 + public static string TrimString(string text, int maxLength) + { + // 유효성 검사 + if (string.IsNullOrEmpty(text) || maxLength <= 0) + { + return string.Empty; + } + + // "..."도 자리수로 포함되므로 자리수가 3 이하라면 "..."을 바로 반환 + if (maxLength <= 3) + { + return "..."; + } + + // 문자열이 최대 자리수를 초과하지 않는다면 그대로 반환 + if (text.Length <= maxLength) + { + return text; + } + + // 문자열 자르기 + "..." + return text.Substring(0, maxLength - 3) + "..."; + } + }