# \[Solved\] Substring() on template instanceName

**URL:** <https://forum.inductiveautomation.com/t/solved-substring-on-template-instancename/21352>\
**Category:** Ignition\
**Created:** [December 11, 2018, 10:21pm UTC](https://forum.inductiveautomation.com/t/solved-substring-on-template-instancename/21352 "2018-12-11T22:21:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbrannen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbrannen/32/3459_2.png) [@sbrannen](https://forum.inductiveautomation.com/u/sbrannen)\
**Post date:** [December 11, 2018, 10:21pm UTC](https://forum.inductiveautomation.com/t/solved-substring-on-template-instancename/21352/1 "2018-12-11T22:21:13Z")

</div>

Hi…

Seems like a bug… crawling in my head… or in Ignition? 🐜

I have a simple template called PartTrackOverlay with a label component. The text property of the label has this binding expression:  
**substring({PartTrackOverlay.instanceName}, 4)** //simple enough, right?

But, it keeps throwing this error.

Exception: Error executing expression binding on  
PartTrackOverlay.PartTrackOverlay.Label.text  
caused by StringIndexOutOfBoundsException: String index out of range: -4

The instanceName of each template is Part1, Part2, …Part32.  
Also… I would have thought the error would be 4, not -4. Perhaps a clue, but I am not sure where it leads.  
The only integer arg it will take is zero. Whatever arg I put in there for the offset shows up in the error as a negative number.

And, after closing the error, _the label is correct_ on the template in the designer.

Any wisdom?

Thanks  
Steve  
v7.9.9

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [December 11, 2018, 11:44pm UTC](https://forum.inductiveautomation.com/t/solved-substring-on-template-instancename/21352/2 "2018-12-11T23:44:19Z")

</div>

It sounds like a timing issue of the label source not being populated before the expression call.  
Wrap it in a try and it should stop the error.

try(substring({PartTrackOverlay.instanceName}, 4),’’)

---

<div class="post-metadata">

**Author:** ![sbrannen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbrannen/32/3459_2.png) [@sbrannen](https://forum.inductiveautomation.com/u/sbrannen)\
**Post date:** [December 12, 2018, 12:41pm UTC](https://forum.inductiveautomation.com/t/solved-substring-on-template-instancename/21352/3 "2018-12-12T12:41:27Z")

</div>

> [@MMaynard](#):
>
> try(substring({PartTrackOverlay.instanceName}, 4),'')

Thank you, that worked! I am still a bit befuddled by the error, especially when a left() or right() call does not produce any error... only substring(). Interesting.

Again, thanks.  
Steve
