# Issue with findfirst on a string

**URL:** <https://discourse.julialang.org/t/issue-with-findfirst-on-a-string/71903>\
**Category:** New to Julia\
**Tags:** strings\
**Created:** [November 22, 2021, 4:44pm UTC](https://discourse.julialang.org/t/issue-with-findfirst-on-a-string/71903 "2021-11-22T16:44:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgriset](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@rgriset](https://discourse.julialang.org/u/rgriset)\
**Post date:** [November 22, 2021, 4:44pm UTC](https://discourse.julialang.org/t/issue-with-findfirst-on-a-string/71903/1 "2021-11-22T16:44:03Z")

</div>

Hi,  
I’m trying to parse a parameter file with julia. I have lines of commentary that I would like not to process . I tried :

```julia
lines = readlines(file)
	for line in lines
		line=split(line,"\t")
		if sizeof(line)>0
			nomParametre = replace(string(line[1])," "=>"")
                        print(findfirst(nomParametre,"#")==nothing)
			if findfirst(nomParametre,"#")==nothing
				print(line)
valeurParametre = string(line[2])

```

When I run this code I’m getting :

```julia
nothing
SubString{String}["# parametres "]
ERROR: LoadError: BoundsError: attempt to access 1-element Array{SubString{String},1} at index [2]

```

The main question is : Why the findfirst function return nothing on String “# parametres” ?

The second question is : Do I need to convert my substring in string like I m doing ? It seems totally illogical to me that substring does not have the same members as string  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![rgriset](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@rgriset](https://discourse.julialang.org/u/rgriset)\
**Post date:** [November 25, 2021, 9:36am UTC](https://discourse.julialang.org/t/issue-with-findfirst-on-a-string/71903/3 "2021-11-25T09:36:58Z")

</div>

Hi rafeal,

Thank you for your answer but you missunderstood my question.

I know that the line “# parametres” doesn’t have a tab that is why I have the line  
if findfirst(nomParametre,“#”)==nothing  
to avoid calling string(line[2]) on this line

My question is to know why the findfirst(nomParametre,“#”) returns “nothing”  
When I write “findfirst(“blabla#”,”#") it works and does not return nothing but it does on my string “nomParametre” which contains a “#”

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [November 25, 2021, 9:47am UTC](https://discourse.julialang.org/t/issue-with-findfirst-on-a-string/71903/4 "2021-11-25T09:47:24Z")

</div>

Check the help text for `findfirst` – `pattern` is the first argument:

```julia
help?> findfirst("#", "#parametre")
  findfirst(pattern::AbstractString, string::AbstractString)
  findfirst(pattern::AbstractPattern, string::String)

  Find the first occurrence of pattern in string. Equivalent to findnext(pattern, string, firstindex(s)).

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> findfirst("z", "Hello to the world") # returns nothing, but not printed in the REPL

  julia> findfirst("Julia", "JuliaLang")
  1:5

julia> findfirst("#", "#parametre")
1:1

```

---

<div class="post-metadata">

**Author:** ![rgriset](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@rgriset](https://discourse.julialang.org/u/rgriset)\
**Post date:** [November 25, 2021, 1:27pm UTC](https://discourse.julialang.org/t/issue-with-findfirst-on-a-string/71903/5 "2021-11-25T13:27:17Z")

</div>

Thank you pfitzsed. Shame on me for a so simple solution 🤗

I checked the find first but couldn’t get my error 🙈
