# List.IndexOf gives -1 when it should give correct results

**URL:** <https://forum.dynamobim.com/t/list-indexof-gives-1-when-it-should-give-correct-results/69088>\
**Category:** Revit\
**Tags:** excel\
**Created:** [October 8, 2021, 2:04pm UTC](https://forum.dynamobim.com/t/list-indexof-gives-1-when-it-should-give-correct-results/69088 "2021-10-08T14:04:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [October 8, 2021, 2:04pm UTC](https://forum.dynamobim.com/t/list-indexof-gives-1-when-it-should-give-correct-results/69088/1 "2021-10-08T14:04:51Z")

</div>

Hi everyone,

I am quite stuck on a (probably) small problem, but i just can’t figure it out!  
I have 2 lists, both containing the same values and i want to match the second list to the first so that they are in the same order.

However, when i try to compare these two lists i am expecting “1 0”, but i am getting “-1 -1” (see screenshot). Both lists contain only strings and duplicating the lists in 2 code blocks seems to work just fine.

I already tried setting “readasstring” to true but to no avail ([List. indexOf giving -1](https://forum.dynamobim.com/t/list-indexof-giving-1/62116))

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/3/63cd90ef22fce30f11a9e0d9766a82c987c01b1f.png)

Kind Regards,  
Daan

Files:  
[2021-10-08 Updating AsBuilt data from Excel to Revit.dyn](https://forum.dynamobim.com/uploads/short-url/wmhgxxtXg2NW4098LHqTu3noBQ5.dyn) (37.3 KB)  
[Zuidbuis AsBuilt Gegevens.xlsx](https://forum.dynamobim.com/uploads/short-url/sn159arsiUZkDFf2zx5r30dX1rg.xlsx) (9.6 KB)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [October 8, 2021, 2:12pm UTC](https://forum.dynamobim.com/t/list-indexof-gives-1-when-it-should-give-correct-results/69088/2 "2021-10-08T14:12:23Z")

</div>

Try checking the string lengths of each list.` List.IndexOf` is working perfectly fine for me in 2.6.

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [October 11, 2021, 1:09pm UTC](https://forum.dynamobim.com/t/list-indexof-gives-1-when-it-should-give-correct-results/69088/3 "2021-10-11T13:09:22Z")

</div>

Hi Nick,

Had some problems with Excel so took a while before i could try this fix, but it does work!  
Thanks a lot for the suggestion, that was indeed the problem (whitespace at the end)!

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/d/cd3acc04ae8e9abcd33570d5f18bb8cad31b2689.png)

---

<div class="post-metadata">

**Author:** ![Hido\_Yalci](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@Hido\_Yalci](https://forum.dynamobim.com/u/Hido_Yalci)\
**Post date:** [October 22, 2021, 2:23pm UTC](https://forum.dynamobim.com/t/list-indexof-gives-1-when-it-should-give-correct-results/69088/4 "2021-10-22T14:23:16Z")

</div>

Change the Code block before Data.ImportExcel to a string. Try with setting value “true” to ‘readAsString’ input in the ‘Data.ImportExcel’ node.
