System.Utf8String.ToString C# (CSharp) Method

ToString() public method

public ToString ( ) : string
return string
        public override unsafe string ToString()
        {
            byte* bytes = stackalloc byte[1 * this.m_StringHeapByteLength];
            byte* pStringHeap = (byte*) this.m_pStringHeap;
            for (int i = 0; i < this.m_StringHeapByteLength; i++)
            {
                bytes[i] = pStringHeap[0];
                pStringHeap++;
            }
            if (this.m_StringHeapByteLength == 0)
            {
                return "";
            }
            int charCount = Encoding.UTF8.GetCharCount(bytes, this.m_StringHeapByteLength);
            char* chars = (char*) stackalloc byte[(2 * charCount)];
            Encoding.UTF8.GetChars(bytes, this.m_StringHeapByteLength, chars, charCount);
            return new string(chars, 0, charCount);
        }
    }

Usage Example

Example #1
0
        /// <summary>
        /// Returns a value stating whether the current <see cref="Utf8String"/> instance contains <paramref name="value"/>.
        /// The specified comparison is used.
        /// </summary>
        public bool Contains(Utf8String value, StringComparison comparison)
        {
            if (value is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
            }

            // TODO_UTF8STRING: Optimize me to avoid allocations.

#if (!NETSTANDARD2_0 && !NETFRAMEWORK)
            return(ToString().Contains(value.ToString(), comparison));
#else
            return(ToString().IndexOf(value.ToString(), comparison) >= 0);
#endif
        }
All Usage Examples Of System.Utf8String::ToString