Skip to content

Instantly share code, notes, and snippets.

@heyajulia
Created November 18, 2024 12:55
Show Gist options
  • Save heyajulia/314e8ede058da7c6b58aaaf965da8111 to your computer and use it in GitHub Desktop.
Save heyajulia/314e8ede058da7c6b58aaaf965da8111 to your computer and use it in GitHub Desktop.
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;
var message = "¡Más amor, por favor!";
var payload = JsonSerializer.Serialize(message, new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
});
var encodedPayload = Encoding.UTF8.GetBytes(payload);
var encodedMessageText = Encoding.UTF8.GetBytes(message);
Console.WriteLine(ContainsSequence(encodedPayload, encodedMessageText));
return;
bool ContainsSequence(ReadOnlySpan<byte> source, ReadOnlySpan<byte> target)
{
return source.IndexOf(target) >= 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment