# \[SOLVED\] Why would 2 strings be not equivalent if I converted them using str()?

**URL:** <https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321>\
**Category:** Ignition\
**Tags:** vision, scripting, ignition79\
**Created:** [December 9, 2020, 1:48am UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321 "2020-12-09T01:48:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [December 9, 2020, 1:48am UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321/1 "2020-12-09T01:48:49Z")

</div>

Good evening,

I have the following code:

```
project.Generic.HMI.messageHandler('Generic', 'info', 'temp_uid: ' + str(temp_uid) +', uid: ' + str(uid))
    if str(temp_uid) == str(uid):
        #do something
    else:
        #do something else

```

My logs show the following message:

```
temp_uid: 0478201032325D, uid: 0478201032325D

```

However the code ‘something else’ is executed. Any clues as to why? The only clue(s) is the values come from 2 different database tables of what should apparently be varchar each.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 9, 2020, 2:14am UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321/2 "2020-12-09T02:14:29Z")

</div>

Hmm, interesting. What is the actual type of the 2 different values? You can log `type(temp_uid)` and `type(uid)`.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [December 9, 2020, 2:22am UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321/3 "2020-12-09T02:22:34Z")

</div>

I will run the test you asked shortly. I just ran a test with the length of each variable and get 14 or 15 depending on the table the value comes from.

I executed the following query on each table:

```
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'myTable'
ORDER BY ORDINAL_POSITION

```

And received the following info:

```
temp_uid table (Returns length 14)
IS_NULLABLE: YES
CHARACTER_MAXIMUM_LENGTH: 24
CHARACTER_OCTET_LENGTH: 24

uid table (Returns length 15)
IS_NULLABLE: NO
CHARACTER_MAXIMUM_LENGTH: 25
CHARACTER_OCTET_LENGTH: 25

```

My hypothesis is the IS\_NULLABLE adds a ‘hidden’ character when set to ‘NO’. Now why it doesn’t convert in Ignition correctly is a mystery to me.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [December 9, 2020, 2:24am UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321/4 "2020-12-09T02:24:48Z")

</div>

Before converting to string using str() :

```
temp_uid: <type 'unicode'>, uid: <type 'unicode'>

```

After converting to string using str():

```
temp_uid: <type 'str'>, uid: <type 'str'>
```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 9, 2020, 2:29am UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321/5 "2020-12-09T02:29:05Z")

</div>

The differences in length is suspicious.

What happens if you print the bytes:

```auto
from org.python.core.util import StringUtil
print StringUtil.toBytes(temp_uid)
print StringUtil.toBytes(uid)

```

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [December 9, 2020, 2:42am UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321/6 "2020-12-09T02:42:41Z")

</div>

```
project.Generic.HMI.messageHandler('Generic', 'info', 'temp_uid: ' + str(StringUtil.toBytes(temp_uid)) +', uid: ' + str(StringUtil.toBytes(uid)))

temp_uid: 
array('b', [48, 52, 55, 53, 50, 48, 49, 48, 53, 54, 51, 51, 53, 68]), 

uid: 
array('b', [48, 52, 55, 53, 50, 48, 49, 48, 53, 54, 51, 51, 53, 68, 32])

```

It’s a space? That gives me another clue.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 9, 2020, 2:48am UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321/7 "2020-12-09T02:48:01Z")

</div>

Yep, don’t think there’s any mystery re: why the comparison fails.

You should probably figure out why one table has whitespace at the end but you can probably make your comparison work immediately by doing something like this:

```auto
if str(temp_uid).strip() == str(uid).strip():
    ...

```

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [December 9, 2020, 2:56am UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321/8 "2020-12-09T02:56:53Z")

</div>

Damn, my apologies for blaming Ignition. Thanks for the help.

---

<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:** [December 9, 2020, 4:21pm UTC](https://forum.inductiveautomation.com/t/solved-why-would-2-strings-be-not-equivalent-if-i-converted-them-using-str/41321/9 "2020-12-09T16:21:03Z")

</div>

I like writing log messages with quotes around things I’m not sure of - helps a lot with this class of bugs.
