# If String Contains

**URL:** <https://forum.inductiveautomation.com/t/if-string-contains/32228>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 13, 2020, 5:01pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228 "2020-02-13T17:01:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [February 13, 2020, 5:01pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/1 "2020-02-13T17:01:48Z")

</div>

Hello There:

Does there exist a function within Perspectives to check if a string contains text. I tried using “indexOf” but it tells me that it is not defined. i.e indexOf(“Hello World”, “ello”).

If anyone could point me in right direction would be appreciated.

---

<div class="post-metadata">

**Author:** ![md.szyman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md.szyman/32/9240_2.png) [@md.szyman](https://forum.inductiveautomation.com/u/md.szyman)\
**Post date:** [February 13, 2020, 5:13pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/2 "2020-02-13T17:13:06Z")

</div>

`indexOf` does work. When I do your example, I get the expected result of `1`.

---

<div class="post-metadata">

**Author:** ![kirsten.chambers](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kirsten.chambers](https://forum.inductiveautomation.com/u/kirsten.chambers)\
**Post date:** [February 13, 2020, 5:13pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/3 "2020-02-13T17:13:41Z")

</div>

If you’re referring to a python script, you’re looking for the “in” operator:

```auto
if "ello" in "Hello World":
    system.perspective.print("ello")

```

If you’re referring to an expression binding, you have your logic correct. Your example returns a value of 1. Where are you attempting to put your expression logic? If it’s outside of an expression binding on a component or an expression tag, you won’t be able to use expression functions.

It also might be the type of quotation marks you’re using. If you copy-pasted your quotation marks (e.g. from the forums here) it gives a configuration error.

---

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [February 13, 2020, 5:15pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/4 "2020-02-13T17:15:44Z")

</div>

Thank you for your reply. This is in a “Transform Script”.

---

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [February 13, 2020, 5:16pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/5 "2020-02-13T17:16:00Z")

</div>

Thank you for your reply. This is in a “Transform Script”. Would that make a difference

---

<div class="post-metadata">

**Author:** ![kirsten.chambers](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kirsten.chambers](https://forum.inductiveautomation.com/u/kirsten.chambers)\
**Post date:** [February 13, 2020, 5:22pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/6 "2020-02-13T17:22:46Z")

</div>

See the first part of my answer. Transform scripts use the Python language. Ignition’s built in expression language is a totally separate language, so if you attempt to use expression language functions in a Python script expecting Python functions, it’s like you’re going to Spain and trying to speak with people there in Chinese 🙂

You might look into the [Ignition docs page here](https://docs.inductiveautomation.com/display/DOC80/Scripting) for a quick primer on scripting. If you’re unfamiliar with Python (or programming in general, really), I highly, HIGHLY recommend searching for some free web tutorials to help you get started in Python. You may also benefit from the courses Inductive Automation offers at [https://www.inductiveuniversity.com/](https://www.inductiveuniversity.com/) (which don’t cover Python, but do cover all the features in Ignition and how to use them 🙂 )

---

<div class="post-metadata">

**Author:** ![jaspinall](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jaspinall](https://forum.inductiveautomation.com/u/jaspinall)\
**Post date:** [February 13, 2020, 5:24pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/7 "2020-02-13T17:24:30Z")

</div>

Thanks for your reply. Now I’m on the right path as i know the difference.

---

<div class="post-metadata">

**Author:** ![corentin.m](https://avatars.discourse-cdn.com/v4/letter/c/53a042/32.png) [@corentin.m](https://forum.inductiveautomation.com/u/corentin.m)\
**Post date:** [July 15, 2021, 2:09pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/8 "2021-07-15T14:09:01Z")

</div>

Am I the only one finding this stupid??

Using different languages within the same software is extremely confusing… This is the first time I encounter such problems with that kind of software. Honestly, this is a mess!

Oh, and auto-completion… 😥 😭

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 15, 2021, 2:23pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/9 "2021-07-15T14:23:42Z")

</div>

> [@corentin.m](#):
>
> Am I the only one finding this stupid??

Yes

---

<div class="post-metadata">

**Author:** ![corentin.m](https://avatars.discourse-cdn.com/v4/letter/c/53a042/32.png) [@corentin.m](https://forum.inductiveautomation.com/u/corentin.m)\
**Post date:** [July 15, 2021, 2:24pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/10 "2021-07-15T14:24:57Z")

</div>

Thanks, this is so helpful

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 15, 2021, 2:28pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/11 "2021-07-15T14:28:39Z")

</div>

Did you need help? Sounded like a rant. Ignition uses expressions and scripts.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 15, 2021, 2:33pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/12 "2021-07-15T14:33:39Z")

</div>

Expressions are assembled into pure java (excluding runScript and friends, naturally) and therefore are blistering fast compared to jython.

Jython is extraordinarily flexible, but at its core is still an interpreted language.

Speed versus Flexibility. Ignition gives you the choice on a point by point basis.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 15, 2021, 2:37pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/13 "2021-07-15T14:37:12Z")

</div>

I don’t you properly appreciate the fact that Ignition has basically made python as a frontend for browsers. I mean python as a front end for browsers has existed, but the fact that you are now also able to tie that in with a Vision/JavaSwing application is a huge accomplishment imo.

Not to mention without perspective, you’d be in the boat of most web developers and and would need to know javascript for your front end and some other language like python for your backend. Ignition has reduced the number of languages you need to know to make a single-page application, not made it worse.

Edit: Responded to the wrong person, this was meant for @corentin.m

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 15, 2021, 2:38pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/14 "2021-07-15T14:38:51Z")

</div>

Why are you replying to me? I don’t need convinced.

---

<div class="post-metadata">

**Author:** ![corentin.m](https://avatars.discourse-cdn.com/v4/letter/c/53a042/32.png) [@corentin.m](https://forum.inductiveautomation.com/u/corentin.m)\
**Post date:** [July 15, 2021, 3:05pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/15 "2021-07-15T15:05:34Z")

</div>

My apologies, it seems that I started a war and it was not my intention here.  
I feel like Ignition is not really easy to understand and use but we all have different experiences…

Can someone point me in the right direction for manipulating strings into gateway or client event scripts?

Thanks

---

<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:** [July 15, 2021, 3:09pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/16 "2021-07-15T15:09:44Z")

</div>

It's very true that expressions vs scripts is one of the things that most confuses new users to the software. I personally don't think there's a way around the learning curve, though - they do different things and have different use cases.

> [@corentin.m](#):
>
> Can someone point me in the right direction for manipulating strings into gateway or client event scripts?

What are you trying to do specifically?  
If you just want a general tutorial, any Python (2.7) tutorial should cover string functions, e.g.:  
[https://www.pitt.edu/~naraehan/python2/string\_methods1.html](https://www.pitt.edu/~naraehan/python2/string_methods1.html)

---

<div class="post-metadata">

**Author:** ![corentin.m](https://avatars.discourse-cdn.com/v4/letter/c/53a042/32.png) [@corentin.m](https://forum.inductiveautomation.com/u/corentin.m)\
**Post date:** [July 15, 2021, 3:13pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/17 "2021-07-15T15:13:28Z")

</div>

What is really not clear to me is that I see stuff in the documentation and I don’t know where it is applicable in the Ignition so I spend time writing stuff to realize at some point that it doesn’t go there.

Should I use Python in scripts?

But yes you’re right, there’s no way around the learning curve.

---

<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:** [July 15, 2021, 3:21pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/18 "2021-07-15T15:21:37Z")

</div>

If it says _script_, then you’re using Python.  
If it says expression, then you’re using our homegrown expression language.

Maybe also helpful:  
[https://docs.inductiveautomation.com/display/DOC81/Scripting+Vs.+SQL+Vs.+Expressions](https://docs.inductiveautomation.com/display/DOC81/Scripting+Vs.+SQL+Vs.+Expressions)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 15, 2021, 3:29pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/19 "2021-07-15T15:29:45Z")

</div>

Have you been to [https://inductiveuniversity.com/](https://inductiveuniversity.com/)? It explains a lot and walks you through almost all of the functionality of Ignition.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 15, 2021, 3:32pm UTC](https://forum.inductiveautomation.com/t/if-string-contains/32228/20 "2021-07-15T15:32:31Z")

</div>

> [@paul-griffith](#):
>
> Maybe also helpful:  
> [Scripting Vs. SQL Vs. Expressions - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Scripting+Vs.+SQL+Vs.+Expressions)

The linked page is really helpful. I liked Paul's comment, but this point is worth more than just one "like".

[Next page](https://forum.inductiveautomation.com/t/if-string-contains/32228.md?page=2)
