Created
November 18, 2024 12:55
-
-
Save heyajulia/314e8ede058da7c6b58aaaf965da8111 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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