Logo

Programming-Idioms

  • Kotlin
  • C++
  • Python
  • Rust
  • PHP
  • Java

Idiom #304 Encode string into UTF-8 bytes

Create the array of bytes data by encoding the string s in UTF-8.

import static java.nio.charset.StandardCharsets.UTF_8;
byte data[] = s.getBytes(UTF_8);
data = s.encode('utf8')
let data = s.into_bytes();
using System.Text;
byte[] data = Encoding.UTF8.GetBytes(s);

New implementation...