# How can I convert a \[\]const u8 to a \[\]const u16?

**URL:** <https://ziggit.dev/t/how-can-i-convert-a-const-u8-to-a-const-u16/13335>\
**Category:** Help\
**Tags:** language\
**Created:** [December 3, 2025, 11:54am UTC](https://ziggit.dev/t/how-can-i-convert-a-const-u8-to-a-const-u16/13335 "2025-12-03T11:54:58Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![squeek502](https://ziggit.dev/user_avatar/ziggit.dev/squeek502/32/409_2.png) [@squeek502](https://ziggit.dev/u/squeek502)\
**Post date:** [December 5, 2025, 9:32am UTC](https://ziggit.dev/t/how-can-i-convert-a-const-u8-to-a-const-u16/13335/14 "2025-12-05T09:32:46Z")

</div>

If you want to allocate on the heap, simplest would just be

```zig
const wtf16 = try std.unicode.wtf8ToWtf16LeAlloc(allocator, wtf8);
defer allocator.free(wtf16);

```

If you want to allocate a buffer, you can get the required size with `std.unicode.calcWtf16LeLen` (returns the required size for allocating `[]u16`)

If the WTF-8 string is a string literal, you can get a WTF-16 LE version of that with `std.unicode.wtf8ToWtf16LeStringLiteral`:

```zig
const wtf16 = std.unicode.wtf8ToWtf16LeStringLiteral("foo");

```

> [@hvbargen](#):
>
> Theoretically, Linux filenames are opaque byte strings. But in many cases, you have to represent them to users or read the file names from somewhere else.

[Relevant](https://ziggit.dev/t/zig-s-lack-of-a-string-type-invalid-values/5425/12)

---

_[View the full topic](https://ziggit.dev/t/how-can-i-convert-a-const-u8-to-a-const-u16/13335)._
