예제 #1
0
        public static string Without(this ReadOnlySpan <char> @this, char value)
        {
            var removeIndex = @this.IndexOf(value);

            if (removeIndex < 0)
            {
                return(@this.ToString());
            }

            if (removeIndex == @this.Length - 1)
            {
                return(@this.Slice(0, removeIndex).ToString());
            }

            var builder = StringBuilderPool.Get(@this.Length - 1);

            builder.Append(@this.Slice(0, removeIndex));

            for (var i = removeIndex; i < @this.Length; i++)
            {
                ref readonly var c = ref @this[i];
        public static string ConcatString(this string @this, ReadOnlySpan <char> value)
        {
#if DEBUG
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }
#endif
            if (@this.Length == 0)
            {
                return(value.ToString());
            }
            if (value.IsEmpty)
            {
                return(@this);
            }

            var builder = StringBuilderPool.Get(@this.Length + value.Length);
            builder.Append(@this);
            builder.Append(value);
            return(StringBuilderPool.GetStringAndReturn(builder));
        }
예제 #3
0
        public static string MakeTitleCase(string s, TextInfo textInfo)
        {
#if DEBUG
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            if (textInfo == null)
            {
                throw new ArgumentNullException(nameof(textInfo));
            }
#endif

            if (s.Length == 0)
            {
                return(s);
            }

            var builder = StringBuilderPool.Get(textInfo.ToLower(s));
            builder[0] = textInfo.ToUpper(s[0]);
            return(StringBuilderPool.GetStringAndReturn(builder));
        }
예제 #4
0
        public static string RemoveChars(this string @this, CharacterSet chars)
        {
#if DEBUG
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }
            if (chars == null)
            {
                throw new ArgumentNullException(nameof(chars));
            }
#endif

            if (@this.Length == 0 || chars.IsEmpty)
            {
                return(@this);
            }

            var builder = StringBuilderPool.Get(@this);
            builder.RemoveChars(chars);
            return(StringBuilderPool.GetStringAndReturn(builder));
        }