예제 #1
0
        public static SubText Trim(this SubText text, bool trimStart = true, bool trimEnd = true)
        {
            if (text.Length == 0)
            {
                return(text);
            }

            int start  = 0;
            int length = text.Length;
            int end    = text.Length - 1;

            if (trimStart)
            {
                for (start = 0; start < length; start++)
                {
                    if (!char.IsWhiteSpace(text[start]))
                    {
                        break;
                    }
                }
            }

            if (trimEnd)
            {
                for (end = length - 1; end >= start; end--)
                {
                    if (!char.IsWhiteSpace(text[end]))
                    {
                        break;
                    }
                }
            }

            return(text.Substring(TextSpan.FromBounds(start, end + 1)));
        }
예제 #2
0
 public static SubText TrimStart(this SubText text)
 {
     return(Trim(text, trimStart: true, trimEnd: false));
 }