# Strip R, G, and B Components from Color as String in Expression

**URL:** <https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [April 4, 2022, 2:54pm UTC](https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999 "2022-04-04T14:54:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [April 4, 2022, 2:54pm UTC](https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999/1 "2022-04-04T14:54:08Z")

</div>

I have a color String that I’m using to format the color of objects (i.e. “RRR,GGG,BBB”). How can I split this into an individual RRR, GGG, or BBB value using Ignition’s expression language?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [April 4, 2022, 3:02pm UTC](https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999/2 "2022-04-04T15:02:37Z")

</div>

I believe I have answered my own question.

red: `split({Template.color},",")[0,0]`

green: `split({Template.color},",")[1,0]`

blue: `split({Template.color},",")[2,0]`

---

<div class="post-metadata">

**Author:** ![austral](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/austral/32/23644_2.png) [@austral](https://forum.inductiveautomation.com/u/austral)\
**Post date:** [April 4, 2022, 3:03pm UTC](https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999/3 "2022-04-04T15:03:52Z")

</div>

yes, no other 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:** [April 4, 2022, 4:00pm UTC](https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999/4 "2022-04-04T16:00:07Z")

</div>

> [@austral](#):
>
> no other way

There is almost always another way. 🤪

red:

```auto
left({Template.color},
     indexOf({Template.color}, ',')
    )

```

green:

```auto
substring({Template.color}, 
          indexOf({Template.color}, ',') + 1, 
          lastIndexOf({Template.color}, ',')
         )

```

blue:

```auto
substring({Template.color}, 
          lastIndexOf({Template.color}, ',') + 1)

```

I never said it was a good way...

That said, if you have many templates, you may want to consider using a custom property to hold a single dataset created by the split(), as your current method makes three datasets, once for each expression.

---

<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:** [April 4, 2022, 4:01pm UTC](https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999/5 "2022-04-04T16:01:44Z")

</div>

Or, since this is sort of begging the question: Why do you need to split RGB values? Why not have 3 separate custom properties for RGB, and use an expression ([`color`](https://docs.inductiveautomation.com/display/DOC81/color)) to create the actual Color value when you need it?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [April 4, 2022, 4:39pm UTC](https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999/6 "2022-04-04T16:39:40Z")

</div>

Using cell update on a style customizer to easily change the color of a fading animation (allow user to change the color using the color picker).

However, I’m running into a bug now with finalizing the bindings. Here’s the setup:

Template named `test`

String tag with value of `255,0,0` bound to internal property `svgColor`

Rectangle component named `Rectangle`

String properties on the rectangle of `color_R`, `color_G`, and `color_B` that are derived from from the internal `svgColor` property using `toInteger(split({test.svgColor},",")[0,0])` / `[1,0]` / `[2,0]` expressions, respectively.

Initially, all of the bindings seem to work. However, once I save, close, and reopen the template I’m getting some errors with `color_G` and `color_B`. They throw this error:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/1/51f65fdcca73e46e10eaa5d2487df619128dd15c.png)

(but not `color_R`?)

Checking the dataset manually by making a temporary dataset property and binding to an expression of `split({[default]svgColor},",")`, I can see that I get 3 rows, 1 column.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/1732e151ebb4996b2c1bf114abd072e8addbbc23.png)

It seems like the bindings still work, despite the errors.

What’s very odd, is if I remove the binding of the tag to `svgColor` (and leave the rest of the bindings the same) I no longer get the errors.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [April 4, 2022, 4:42pm UTC](https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999/7 "2022-04-04T16:42:40Z")

</div>

> [@JordanCClark](#):
>
> > [@austral](#):
> >
> > no other way
> 
> There is almost always another way. 🤪
> 
> red:
> 
> ```python
> left({Template.color},
> indexOf({Template.color}, ',')
> )
> 
> ```
> 
> green:
> 
> ```python
> substring({Template.color}, 
> indexOf({Template.color}, ',') + 1, 
> lastIndexOf({Template.color}, ',')
> )
> 
> ```
> 
> blue:
> 
> ```python
> substring({Template.color}, 
> lastIndexOf({Template.color}, ',') + 1)
> 
> ```
> 
> I never said it was a good way...
> 
> That said, if you have many templates, you may want to consider using a custom property to hold a single dataset created by the split(), as your current method makes three datasets, once for each expression.

That was my initial thought coming from using Excel so much 😅

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [April 12, 2022, 10:13pm UTC](https://forum.inductiveautomation.com/t/strip-r-g-and-b-components-from-color-as-string-in-expression/57999/8 "2022-04-12T22:13:47Z")

</div>

I have found that the `toColor()` function works in the Cell Update binding Value column. So I’m able to do a `toColor(<color_tag>+",150")` which is a much nicer solution
