# Coersing into a type

**URL:** <https://discourse.julialang.org/t/coersing-into-a-type/140299>\
**Category:** General Usage\
**Tags:** strings\
**Created:** [October 27, 2026, 10:49pm UTC](https://discourse.julialang.org/t/coersing-into-a-type/140299 "2026-10-27T22:49:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![freeman](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@freeman](https://discourse.julialang.org/u/freeman)\
**Post date:** [October 27, 2026, 10:49pm UTC](https://discourse.julialang.org/t/coersing-into-a-type/140299/1 "2026-10-27T22:49:30Z")

</div>

Sorry but I don’t know a better term than coercing.

Suppose that I read a set of strings and some times all of those strings can all be converted to InlineStrings.String15, which I prefer for performance, and some times not.

What is the cleanest way to do this?

Here’s one that I can think of, but I don’t like because I hate exceptions:

```julia-auto
s1 = ["kdjhfgksjdhfgkljsdhf", "lkjsdflskdflskdjflkfljs", "ldkfglkdfjglkdjfglkd"]
s2 = ["dfg", "dfg", "hkfj"]

maybeconvert(ss) = try
    InlineStrings.String15.(ss)
catch
    ss
end

maybeconvert(s1) # Vector{String}
maybeconvert(s2) # Vector{String15}

```
