# Replacing strings in specific position indices as in \`str\_sub()\` in \`stringr\`

**URL:** <https://discourse.julialang.org/t/replacing-strings-in-specific-position-indices-as-in-str-sub-in-stringr/90187>\
**Category:** General Usage\
**Tags:** strings, unicode\
**Created:** [November 13, 2022, 10:37am UTC](https://discourse.julialang.org/t/replacing-strings-in-specific-position-indices-as-in-str-sub-in-stringr/90187 "2022-11-13T10:37:55Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 14, 2022, 2:16pm UTC](https://discourse.julialang.org/t/replacing-strings-in-specific-position-indices-as-in-str-sub-in-stringr/90187/9 "2022-11-14T14:16:00Z")

</div>

> [@rafael.guerra](#):
>
> I think that for Unicode strings, we should use the extended `graphemes` function

I’m a bit skeptical that this is what you would want in a realistic application. How is the data being generated that you know specific graphemes indices to replace?

Most commonly, string indices are obtained by searching/iterating a string, in which case you want the actual index and not a character or grapheme index, and this is what string slicing and substrings already do. See also my comment in another thread [Substring function? - #27 by stevengj](https://discourse.julialang.org/t/substring-function/76675/27)

> The basic argument is that a variable-width encoding with non-consecutive codepoint indices is a good tradeoff to make (memory efficiency + speed, at the cost of less-intuitive indexing) because “give me the m-th codepoint” or “or give me the substring from codepoints m to n” is extremely uncommon in (correct) string-handling code, as opposed to “give me the substring at opaque indices I found in a previous search/loop”.

and the surrounding discussion.

“Give me the m:n-th user-perceived ‘characters’ (i.e. graphemes)” is something that people commonly ask for in their first steps of using strings in Julia, which is why I added a `graphemes(s, m:n)` function, but when you go farther you typically find that this is not what is needed at all.

---

_[View the full topic](https://discourse.julialang.org/t/replacing-strings-in-specific-position-indices-as-in-str-sub-in-stringr/90187)._
