퇴근5분전

 
간단해서.. 그닥.. 기록할내용은 없는듯...


사용법 : 
   this.Text = "ABCCC".Left(2);

확장메서드 구현 : 
 

 /// <summary>
    /// VB.Left() 함수를 구현한 확장메서드임.
    /// </summary>
    internal static class exString
    {
        /// <summary>
        ///  VB.Left() 함수를 구현한 확장메서드임.
        /// </summary>
        /// <param name="targetstr"></param>
        /// <param name="length">왼쪽에서~~ </param>
        /// <returns></returns>
        internal static string Left(this string targetstr, int length)
        {
            if (length < 0) // -1이 들어왔을때...
                throw new Exception("'Length' 인수는 0보다 크거나 같아야 합니다.");

            if (targetstr.Length > length )
            {
                return targetstr.Substring(0, length);
            }
            else
            {
                return targetstr;
            }
        }

        /// <summary>
        /// VB.Right() 함수를 구현한 확장메서드
        /// </summary>
        /// <param name="targetstr"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        internal static string Right(this string targetstr, int length)
        {
            if (length < 0)
            {
                throw new Exception("'Length' 인수는 0보다 크거나 같아야 합니다.");
            }

            if (targetstr.Length > length)
            {
                return targetstr.Substring(targetstr.Length - length, length);
            }
            else
            {
                return targetstr;
            }
        }
    }


2010, 2, 25 일 Right 추가..