# StringIndexError some time comes unexpectedly

**URL:** <https://discourse.julialang.org/t/stringindexerror-some-time-comes-unexpectedly/36174>\
**Category:** General Usage\
**Tags:** strings\
**Created:** [March 19, 2020, 4:42am UTC](https://discourse.julialang.org/t/stringindexerror-some-time-comes-unexpectedly/36174 "2020-03-19T04:42:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [March 19, 2020, 4:42am UTC](https://discourse.julialang.org/t/stringindexerror-some-time-comes-unexpectedly/36174/1 "2020-03-19T04:42:53Z")

</div>

StringIndexError some time comes unexpectedly.

Does anybody have this type of error? How to deal with it.  
I just do the next code to solve the problem, just change the index from 701 to 702 =)). Does anybody suggest other solutions?

> try  
> f=findfirst(“blabla”,page[end-701:end])[1]  
> return page[1:end-701+f-3]  
> catch  
> f=findfirst(“blabla”,page[end-702:end])[1]  
> return page[1:end-702+f-3]  
> end

---

<div class="post-metadata">

**Author:** ![laborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laborg/32/5474_2.png) [@laborg](https://discourse.julialang.org/u/laborg)\
**Post date:** [March 19, 2020, 6:12am UTC](https://discourse.julialang.org/t/stringindexerror-some-time-comes-unexpectedly/36174/2 "2020-03-19T06:12:40Z")

</div>

You have to be careful when indexing into strings in Julia. It is important to understand that certain characters can take up _more than one index_, and therefore errors can occur if you blindly assume that every `page[i]` is valid.  
This section of the manual should help you come up with a solution to your problem: [Strings · The Julia Language](https://docs.julialang.org/en/v1/manual/strings/#Unicode-and-UTF-8-1)

---

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [March 19, 2020, 11:40pm UTC](https://discourse.julialang.org/t/stringindexerror-some-time-comes-unexpectedly/36174/3 "2020-03-19T23:40:10Z")

</div>

Thank you so much.
