private static ReadOnlySpan <Char> PalindromeStrip(ReadOnlySpan <Char> span) { // First we need to build the string without any punctuation or whitespace or any other unrelated-to-reading characters Char[] builder = new Char[span.Length]; Int32 b = 0; Span <Char> glyphChars = new Char[2]; foreach (Glyph s in span.EnumerateGlyphs()) { if (Glyph.IsLetterOrDigit(s)) { switch (s.EncodeToUtf16(glyphChars)) { case 1: builder[b++] = glyphChars[0]; break; case 2: builder[b++] = glyphChars[0]; builder[b++] = glyphChars[1]; break; } } } return(builder.AsSpan().Slice(0, b)); }
private static ReadOnlySpan <Char> PalindromeStrip(ReadOnlySpan <Char> span) { // First we need to build the string without any punctuation or whitespace or any other unrelated-to-reading characters Char[] builder = new Char[span.Length]; Int32 b = 0; foreach (Char s in span) { if (!(Char.IsControl(s) || Char.IsPunctuation(s) || Char.IsSeparator(s) || Char.IsSymbol(s) || Char.IsWhiteSpace(s))) { builder[b++] = s; } } return(builder.AsSpan().Slice(0, b)); }