# String \<=\> Unicode Comparison?

**URL:** <https://forum.inductiveautomation.com/t/string-unicode-comparison/77076>\
**Category:** Ignition\
**Created:** [July 28, 2023, 3:51pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076 "2023-07-28T15:51:17Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Rzewnicki](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Mark\_Rzewnicki](https://forum.inductiveautomation.com/u/Mark_Rzewnicki)\
**Post date:** [July 28, 2023, 3:51pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/1 "2023-07-28T15:51:18Z")

</div>

I have an array of ASCII codes coming from a PLC into Ignition - this corresponds to a string in the PLC. I am doing the following:

VALUES = [list of ASCII codes]

S = ''.join(chr(v) for v in VALUES)

test\_string = [string equivalent to S]

print S==test\_string

This always returns False, even though S and test\_string are type (str) and clearly the same. I think this has something to with chr() and Unicode vs. String, but I don't really know what I'm talking about here.

My goal is to compare the incoming "string" with a predefined reference string - could someone please point me in the right direction on this? I would prefer not decompose the reference string into ASCII characters and compare the arrays, but I will if it's the only way...

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 28, 2023, 3:57pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/2 "2023-07-28T15:57:44Z")

</div>

Any example of a non-working VALUES list?

```python

VALUES = [72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]

S = ''.join(chr(v) for v in VALUES)

print VALUES
print S

test_string = u'Hello world'
S == test_string

```

```plaintext
[72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
Hello world
True

```

---

<div class="post-metadata">

**Author:** ![Mark\_Rzewnicki](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Mark\_Rzewnicki](https://forum.inductiveautomation.com/u/Mark_Rzewnicki)\
**Post date:** [July 28, 2023, 4:06pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/3 "2023-07-28T16:06:18Z")

</div>

![bad at writing programs](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/1/c1135ff72282ee60fb7fd5bc54b1ecaf0b583fa6.png)

Maybe I'm doing something else wrong here? Thank you very much

---

<div class="post-metadata">

**Author:** ![Mark\_Rzewnicki](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Mark\_Rzewnicki](https://forum.inductiveautomation.com/u/Mark_Rzewnicki)\
**Post date:** [July 28, 2023, 4:07pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/4 "2023-07-28T16:07:34Z")

</div>

last line should be S==test\_string but this produces the same result

---

<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 28, 2023, 4:08pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/5 "2023-07-28T16:08:30Z")

</div>

Your sample data has ASCII NUL characters. You aren't excluding them, so your comparision string will have to have them too.

---

<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 28, 2023, 4:09pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/6 "2023-07-28T16:09:21Z")

</div>

Try using `print repr(S)` to see what you really have.

---

<div class="post-metadata">

**Author:** ![Mark\_Rzewnicki](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Mark\_Rzewnicki](https://forum.inductiveautomation.com/u/Mark_Rzewnicki)\
**Post date:** [July 28, 2023, 4:13pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/7 "2023-07-28T16:13:38Z")

</div>

I see, there is more going on there than I thought.

I need the strings to be be dynamically sized (hence the 20 character limit), so I guess I will do the comparisons on the ASCII code lists.

Thank you very much

---

<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 28, 2023, 4:18pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/8 "2023-07-28T16:18:27Z")

</div>

Or stop building the string on the first null. Most PLC drivers will help you read strings using the brand's conventions, so you don't have to go through these contortions. What kind of PLC is this?

{ For example specific to your usage, see the `@string` and `@utf8` modifiers in §8.3.4 of [my EtherNet/IP Driver Manual](https://www.automation-pros.com/enip1/UserManual.pdf). }

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 28, 2023, 5:07pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/9 "2023-07-28T17:07:34Z")

</div>

EDIT: Sorry, would have answered sooner, but I was having lunch with my daughter. Not many more days before she's back off to college... 🙂

As Phil mentioned, the PLC driver should ideally have a format for strings.

If, however, you're stuck with what you have (some MODBUS-y things come to mind), then finding the location of the first null should work:

```python
S = ''.join(chr(v) for v in VALUES)[:VALUES.index(0)]

```

Example:

```python
test_string = u'545276'

VALUES = [53,52,53,50,55,54, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

S = ''.join(chr(v) for v in VALUES)[:VALUES.index(0)]

print VALUES
print S
S == test_string

```

```plaintext
[53, 52, 53, 50, 55, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
545276
True

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 29, 2023, 3:58pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/10 "2023-07-29T15:58:39Z")

</div>

`itertools` has something for this case (it usually does):

```python
from itertools import takewhile
S = ''.join(chr(v) for v in takewhile(lambda x: x != 0, VALUES))

```

Might not be worth it in this case, but I like `itertools` a lot and try to showcase its possibilities when I can !

---

<div class="post-metadata">

**Author:** ![Mark\_Rzewnicki](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@Mark\_Rzewnicki](https://forum.inductiveautomation.com/u/Mark_Rzewnicki)\
**Post date:** [August 7, 2023, 4:43pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/11 "2023-08-07T16:43:03Z")

</div>

Sorry, revisiting after a delay...

These are AB Micro800 PLCs, so yes it is Modbus and I believe I'm stuck with what I have, unless we see that Micro800 EtherNet driver I've seen mentioned on here 🙂

I was able to hide the ugliness in a function and it seems to be working pretty well. Thanks very much

---

<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:** [August 7, 2023, 5:03pm UTC](https://forum.inductiveautomation.com/t/string-unicode-comparison/77076/12 "2023-08-07T17:03:42Z")

</div>

> [@Mark\_Rzewnicki](#):
>
> unless we see that Micro800 EtherNet driver I've seen mentioned on here

It was released in April, latest is here:

> [@Automation Professionals' EtherNet/IP Communication Suite V2](https://forum.inductiveautomation.com/t/automation-professionals-ethernet-ip-communication-suite-v2/68190/103):
>
> A regression fix (@barrier support) and a fix for the slightly wider array optimizations of v2.1.1. Arbitrary unbrowsed symbol support is close... (Intended for ML8xx and Omron NJ/NX applications.) For Ignition v8.1+: v2.1.4.231991530 Latest official release is on my [Module Sales](https://www.automation-pros.com/modulesales.html) page, as usual.
