# Extending Base.\_searchindex to "findall"?

**URL:** <https://discourse.julialang.org/t/extending-base-searchindex-to-findall/78938>\
**Category:** General Usage\
**Created:** [April 3, 2022, 10:29am UTC](https://discourse.julialang.org/t/extending-base-searchindex-to-findall/78938 "2022-04-03T10:29:38Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [April 3, 2022, 10:47am UTC](https://discourse.julialang.org/t/extending-base-searchindex-to-findall/78938/2 "2022-04-03T10:47:41Z")

</div>

> [@Ahmed\_Salih](#):
>
> ```julia
> TextToSearch = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
> 
> nTextToSearch = length(TextToSearch)
> 
> TranscodedText = transcode(UInt8,TextToSearch)[:]
> 
> Needle = "Lorem"
> SearchNeedle = codeunits(Needle)
> nSearchNeedle = ncodeunits(Needle)
> 
> ```

Doing a google search I was fortunate enough to find this answer from 2 years ago, on a question I had asked my self… 😅

> [@Finding position of a sequence in a UInt8 array?](https://discourse.julialang.org/t/finding-position-of-a-sequence-in-a-uint8-array/45757/9):
>
> It’s the starting index for the search, the same as the [start argument of findnext](https://docs.julialang.org/en/latest/base/strings/#Base.findnext-Tuple%7BAbstractString,AbstractString,Integer%7D) — it says to search starting at byte 1. Passing 2 means to search starting at byte 2. In this way, you can find multiple occurrences: i = Base.\_searchindex(a, [0x90,0xea,0x00], 1) Base.\_searchindex(a, [0x90,0xea,0x00], i+1) # finds the second occurrence, if any

Therefore a working loop can simply be done as:

```julia
idHits = Vector{Int64}()
ind = 0

while true
    ind = Base._searchindex(TranscodedText, SearchNeedle, ind+1)
    if ind == 0
        break
    end
    push!(idHits,ind)
end

```

Kind regards

---

_[View the full topic](https://discourse.julialang.org/t/extending-base-searchindex-to-findall/78938)._
