# Extract data from a string

**URL:** <https://forum.universal-robots.com/t/extract-data-from-a-string/39912>\
**Category:** URScript\
**Created:** [May 19, 2025, 11:31am UTC](https://forum.universal-robots.com/t/extract-data-from-a-string/39912 "2025-05-19T11:31:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luca-0](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@luca-0](https://forum.universal-robots.com/u/luca-0)\
**Post date:** [May 19, 2025, 11:31am UTC](https://forum.universal-robots.com/t/extract-data-from-a-string/39912/1 "2025-05-19T11:31:59Z")

</div>

Hello,

I’m looking for the most efficient way to extract certain data from a string so I can use it to alter poses.

the string looks somewhat like this: “TRXP00R00000060(001,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,-179246,-3333,8852,057)”  
I want to extract:  
-179246  
-3333  
8852  
057

What is the best way to extract these numbers and put them in their own variable?  
the numbers will change and impact the program so its important to get it right every time.

---

<div class="post-metadata">

**Author:** ![EV1](https://avatars.discourse-cdn.com/v4/letter/e/5fc32e/32.png) [@EV1](https://forum.universal-robots.com/u/EV1)\
**Post date:** [May 19, 2025, 4:50pm UTC](https://forum.universal-robots.com/t/extract-data-from-a-string/39912/2 "2025-05-19T16:50:49Z")

</div>

I would look through the UR script manual under the str\_ commands. You might be able to do it with str\_find and str\_sub depending on how consistent the zeros and ones before the value are.

One possibility is to edit what is sending the string to add an identifier before each of the values you want. Something like:

str\_var = “TRXP00R00000060(001,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,a-179246,b-3333,c8852,d057)”  
first\_loc = str\_find(str\_var, “a”) //finds location of a  
end\_loc = str\_find(str\_var, “,”, first\_loc) //finds location of first comma after a  
var1 = str\_sub(str\_var, first\_loc, end\_loc-first\_loc) //separates out the first variable.

Hmmm, might be an easier way than this, but should provide a decent starting point. If you can’t add an identifier, maybe try using str\_find and str\_sub to remove the stuff before the first parenthesis and loop extracting each number up to the next comma. Then discard all the values that are zero or one.

---

<div class="post-metadata">

**Author:** ![k.s.cameron](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@k.s.cameron](https://forum.universal-robots.com/u/k.s.cameron)\
**Post date:** [May 21, 2025, 7:53pm UTC](https://forum.universal-robots.com/t/extract-data-from-a-string/39912/3 "2025-05-21T19:53:57Z")

</div>

split() is a method in C and Java and most of Polyscope uses things like that. But I’m not near a manual or system to confirm this. it will return an array without the commas as parts of the strings.

-ken c

---

<div class="post-metadata">

**Author:** ![travis1](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@travis1](https://forum.universal-robots.com/u/travis1)\
**Post date:** [May 22, 2025, 2:09pm UTC](https://forum.universal-robots.com/t/extract-data-from-a-string/39912/4 "2025-05-22T14:09:52Z")

</div>

Where is the string coming from? It looks to be maybe a telegram from a SensoPart camera?

---

<div class="post-metadata">

**Author:** ![luca-0](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@luca-0](https://forum.universal-robots.com/u/luca-0)\
**Post date:** [May 26, 2025, 5:44am UTC](https://forum.universal-robots.com/t/extract-data-from-a-string/39912/5 "2025-05-26T05:44:21Z")

</div>

yes, you are right.  
Its a String from a sensopart camera.

I got it a working program using str\_sub and str\_find.

---

<div class="post-metadata">

**Author:** ![travis1](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@travis1](https://forum.universal-robots.com/u/travis1)\
**Post date:** [May 27, 2025, 1:27pm UTC](https://forum.universal-robots.com/t/extract-data-from-a-string/39912/6 "2025-05-27T13:27:48Z")

</div>

you can also use Sensopart’s script “visor\_getAdditionalData(0,0)”.

so something like… _to\_num(visor\_getAdditionalData(1, 8)_ where 1 is the camera number and 8 is data you added to the telegram. telegrams will always need to be ASCII and some conversions may need to be done for INT or float.

But all detectors have a bunch or extra values you can add to telegram just be sure the first part of the telegram start with detector results and then a pose. then add any additional data you want and use visor\_getAdditionalData(0,0) to pull into Polyscope. I will usually just assign these values to a variable either right after taking the image or in a thread.

---

<div class="post-metadata">

**Author:** ![charlesrhoward](https://avatars.discourse-cdn.com/v4/letter/c/c77e96/32.png) [@charlesrhoward](https://forum.universal-robots.com/u/charlesrhoward)\
**Post date:** [May 28, 2025, 3:49am UTC](https://forum.universal-robots.com/t/extract-data-from-a-string/39912/7 "2025-05-28T03:49:01Z")

</div>

You can use re.findall in Python to grab those numbers from the string. Here’s a quick example:  
import re

```auto
s = "TRXP00R00000060(001,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,-179246,-3333,8852,057)"
numbers = re.findall(r"-?\d+", s)
x, y, z, r = map(int, numbers[-4:]) # Grab the last 4 numbers

```

This gets you the last 4 values every time, no matter how the rest of the string changes. Hope it helps!
