# Vision Scripting: IndexOf and LastIndexOf / Substring

**URL:** <https://forum.inductiveautomation.com/t/vision-scripting-indexof-and-lastindexof-substring/69241>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [January 31, 2023, 9:32pm UTC](https://forum.inductiveautomation.com/t/vision-scripting-indexof-and-lastindexof-substring/69241 "2023-01-31T21:32:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seth\_Kahle](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@Seth\_Kahle](https://forum.inductiveautomation.com/u/Seth_Kahle)\
**Post date:** [January 31, 2023, 9:32pm UTC](https://forum.inductiveautomation.com/t/vision-scripting-indexof-and-lastindexof-substring/69241/1 "2023-01-31T21:32:25Z")

</div>

Trying to write a script that breaks apart a string. I realize I can't use the expression functions, but I can't seem to figure out how to find the index of a colon in a string, and then take a substring up to that index. I've found some previous posts about how to do substrings, but they are all using literal values, and I need to substitute a variable using something equivalent to IndexOf and LastIndexOf.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [January 31, 2023, 9:37pm UTC](https://forum.inductiveautomation.com/t/vision-scripting-indexof-and-lastindexof-substring/69241/2 "2023-01-31T21:37:31Z")

</div>

If you show an example of the string and what you want in the end, it would help give a solution. I would assume you want to use the python split() fuction.

[Python String | split() - GeeksforGeeks](https://www.geeksforgeeks.org/python-string-split/)

---

<div class="post-metadata">

**Author:** ![Seth\_Kahle](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@Seth\_Kahle](https://forum.inductiveautomation.com/u/Seth_Kahle)\
**Post date:** [January 31, 2023, 10:16pm UTC](https://forum.inductiveautomation.com/t/vision-scripting-indexof-and-lastindexof-substring/69241/3 "2023-01-31T22:16:37Z")

</div>

What I am trying to do is pass some information into the Alarm Lists from my UDT configurations, and then use that to create a hyperlink to object the corresponding instances faceplate of the UDT associated with the alarm. In my case, I want to do this on a double click.

My issue was that _alarmEvent.displayPath_ is not a string, but some type of object that prints as a string, so the .index() or .rindex() methods were failing. To get around this, I had to explicitly cast alarmEvent.display path to string first.

```auto
def onDoubleClicked(self, alarmEvent):
	
	#Break apart the alarm DisplayPath property into components that can be used to open a faceplate
	DisplayPath = str(alarmEvent.displayPath)
	FaceplatePath = DisplayPath[0:DisplayPath.index(":")]
	PLC = DisplayPath[DisplayPath.index(":")+1:DisplayPath.rindex(":")]
	Instance = DisplayPath[DisplayPath.rindex(":")+1:]

	#Open the faceplate associated with this alarm
	system.nav.openWindowInstance(FaceplatePath, {'PLC' : PLC, 'Instance' : Instance})

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 31, 2023, 11:01pm UTC](https://forum.inductiveautomation.com/t/vision-scripting-indexof-and-lastindexof-substring/69241/4 "2023-01-31T23:01:36Z")

</div>

`type(alarmEvent.displayPath)` would show you that it's a `StringPath`, which you can (as you noted) convert to a string, or, depending on what you want to do, you could operate on its parts directly, via `alarmEvent.displayPath.parts`, which might make what you're trying to do easier. It's a StringPath instead of a plain string for ease of parsing and comparison throughout the rest of the system:  
[https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.24/com/inductiveautomation/ignition/common/StringPath.html](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.24/com/inductiveautomation/ignition/common/StringPath.html)

---

<div class="post-metadata">

**Author:** ![Seth\_Kahle](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@Seth\_Kahle](https://forum.inductiveautomation.com/u/Seth_Kahle)\
**Post date:** [February 1, 2023, 4:49am UTC](https://forum.inductiveautomation.com/t/vision-scripting-indexof-and-lastindexof-substring/69241/5 "2023-02-01T04:49:46Z")

</div>

I actually got smarter about this and just passed the FaceplatePath, PLC, and Instance name into Associated Data fields from UDT parameters, and then was able very easily get them from alarmEvent.xxx in the Alarm List scripts. This also freed up the Display Path column to be used for more informational text about the alarm. All this python string handling has become obsolete for me, but it's always good to learn something new!
