If String Contains

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.

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

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

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.

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

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

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 :slight_smile:

You might look into the Ignition docs page here 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/ (which don’t cover Python, but do cover all the features in Ignition and how to use them :slight_smile: )

1 Like

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

1 Like

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… :disappointed_relieved: :sob:

Yes

Thanks, this is so helpful

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

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.

2 Likes

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

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

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

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.

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

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.

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

5 Likes

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

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