# Remove Space from string data

**URL:** <https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [December 13, 2021, 7:02pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067 "2021-12-13T19:02:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![urvishmehta92](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@urvishmehta92](https://forum.inductiveautomation.com/u/urvishmehta92)\
**Post date:** [December 13, 2021, 7:02pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/1 "2021-12-13T19:02:38Z")

</div>

Hello Everyone,  
I am scanning a barcode from scanner and the data I receive is a string type, Now I see the data being populated but It has a space in front of data. So first character is space and then actual characters. “1Z096V4Y0657697557” Is there a way I can get rid of those extra characters? Interestingly I see boxes here but in actual tag it’s a space.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [December 13, 2021, 7:08pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/2 "2021-12-13T19:08:33Z")

</div>

You can use Python’s [strip](https://docs.python.org/2.7/library/stdtypes.html?highlight=strip#str.strip) function, which will remove any spaces in the string.

---

<div class="post-metadata">

**Author:** ![urvishmehta92](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@urvishmehta92](https://forum.inductiveautomation.com/u/urvishmehta92)\
**Post date:** [December 13, 2021, 7:51pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/3 "2021-12-13T19:51:22Z")

</div>

I tried it but I think I might be doing it in a wrong manner as I don’t know python much. Let’s say I have  
" Hello" in tag 9. What do I write? strip(tag9) or tag9.strip() ? and the result after strip will be stored in same tag9 ?

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [December 13, 2021, 7:59pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/4 "2021-12-13T19:59:48Z")

</div>

I’m assuming `tag9` is a variable name. If that’s the case, then you can do this:

```python
bar_str = tag9.strip()

```

Otherwise, you’ll first need to read in the tag value. One way you can do this is by using [`system.tag.readBlocking()`](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking) or `system.tag.readAsync()`.

---

<div class="post-metadata">

**Author:** ![urvishmehta92](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@urvishmehta92](https://forum.inductiveautomation.com/u/urvishmehta92)\
**Post date:** [December 14, 2021, 12:44pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/5 "2021-12-14T12:44:33Z")

</div>

I tried the same way. I think I know why it isn’t working. It shows me space in data value but when I copy that tag in notepad or here it looks like - “1Z096V4Y0657697557”.even this website is removing those characters. I am not sure if I can upload a picture here. As you see it’s not a space, It’s a character which is not readable by tag and it’s showing space.

Is there a command to delete first and last character from received string?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 14, 2021, 12:50pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/6 "2021-12-14T12:50:58Z")

</div>

> [@urvishmehta92](#):
>
> Is there a command to delete first and last character from received string?

```auto
test = 'First Character'
print test[1:]

test = 'Last Character'
print test[:-1]

```

output

```auto
>>> 
irst Character
Last Characte
>>> 

```

---

<div class="post-metadata">

**Author:** ![urvishmehta92](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@urvishmehta92](https://forum.inductiveautomation.com/u/urvishmehta92)\
**Post date:** [December 14, 2021, 12:59pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/7 "2021-12-14T12:59:22Z")

</div>

Wow. This was big help, I tried and it works.

**tag1 = system.tag.read("[default]Barcode Scanner/Barcode Scanner Data")**

**tag2 = tag1.value**  
**print tag2**

**tag3 = tag2[1:-1]**

**print tag3**

---

<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 14, 2021, 5:39pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/8 "2021-12-14T17:39:47Z")

</div>

Somewhat safer would be to `print repr(tag1)` (to see the explicit character code(s) used as the prefix and suffix) and then pass them to strip, as in `tag2.strip("\x01")`

---

<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:** [December 14, 2021, 7:43pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/9 "2021-12-14T19:43:40Z")

</div>

@urvishmehta92 you can upload by clicking the upload button…

![1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/8/58ccb5ab23e06d22fecfdd0e9bd256da6aa51a6f.png)

For code and formatted text attach by using preformatted text…

![2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/3/53d12a39267ec38d4753627eedd4849a0a025c30.png)

---

<div class="post-metadata">

**Author:** ![urvishmehta92](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@urvishmehta92](https://forum.inductiveautomation.com/u/urvishmehta92)\
**Post date:** [December 14, 2021, 7:56pm UTC](https://forum.inductiveautomation.com/t/remove-space-from-string-data/54067/10 "2021-12-14T19:56:57Z")

</div>

OMG! I don’t know how I missed it. 🤦‍♂️

Thank you for pointing that out.
