# How to replace the charactors in the string?

**URL:** <https://discourse.julialang.org/t/how-to-replace-the-charactors-in-the-string/30778>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 6, 2019, 5:35am UTC](https://discourse.julialang.org/t/how-to-replace-the-charactors-in-the-string/30778 "2019-11-06T05:35:08Z")\
**Posts on this page:** 1\
**Showing post:** 35

<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 7, 2019, 6:59pm UTC](https://discourse.julialang.org/t/how-to-replace-the-charactors-in-the-string/30778/35 "2019-11-07T18:59:08Z")

</div>

> [@laborg](#):
>
> The speed is now getting towards Perl. I’m not sure if the Perl version allocates memory in each iteration…

Perl uses reference counting for memory management, and it is probably more efficient for allocating and then discarding many small strings like you are doing here. (Indeed, working with lots of small strings is probably the main situation that Perl’s memory management is optimized for.) (Julia uses [mark-and-sweep](https://discourse.julialang.org/t/details-about-julias-garbage-collector-reference-counting/18021) garbage collection, because reference counting imposes other tradeoffs for compiled and multithreaded code.)

The real question here: in what circumstance is the `tr` operation on small strings performance-critical? In a given realistic setting, there is usually a way to avoid doing lots of re-allocations in your inner loop…

---

_[View the full topic](https://discourse.julialang.org/t/how-to-replace-the-charactors-in-the-string/30778)._
