# Can the length of a string be calculated in a flow?

**URL:** <https://community.homey.app/t/can-the-length-of-a-string-be-calculated-in-a-flow/114159>\
**Category:** Questions & Help\
**Created:** [August 10, 2024, 5:02am UTC](https://community.homey.app/t/can-the-length-of-a-string-be-calculated-in-a-flow/114159 "2024-08-10T05:02:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Icepick](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/icepick/32/56463_2.png) [@Icepick](https://community.homey.app/u/Icepick)\
**Post date:** [August 10, 2024, 5:02am UTC](https://community.homey.app/t/can-the-length-of-a-string-be-calculated-in-a-flow/114159/1 "2024-08-10T05:02:23Z")

</div>

For my flow I need the length of my string… is there any way to do this? I tried {{ length ( ‘test’ ) }} and several variations to this but no luck so far.

 ![Screenshot 2024-08-10 at 07.01.51](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/e/2e2693c0a852bb52ab3c6aa202cb7e457451539f.jpeg)

---

<div class="post-metadata">

**Author:** ![FKey](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/fkey/32/14793_2.png) [@FKey](https://community.homey.app/u/FKey)\
**Post date:** [August 10, 2024, 7:26am UTC](https://community.homey.app/t/can-the-length-of-a-string-be-calculated-in-a-flow/114159/2 "2024-08-10T07:26:12Z")

</div>

The [better logic](https://homey.app/en-nl/app/net.i-dev.betterlogic/Better-Logic-Library/) app has much more options, maybe this command works with that app

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [August 10, 2024, 3:17pm UTC](https://community.homey.app/t/can-the-length-of-a-string-be-calculated-in-a-flow/114159/3 "2024-08-10T15:17:40Z")

</div>

Can be done with  
`{{ size("[string]") }}`

But it returns the string `[6]` instead of a numeric `6` ( in case the calculated length is 6 that is)

I could only solve it with use of a little Homeyscript code

 ![Screenshot from 2024-08-10 16-33-27](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/b/fb29d4799a360048acd1c66db85302e0c7da07f5.png)

The code:

```auto
// Filter the number out of the string size
var response = args[0];
const stringSize = '' + response.split("[")[1].split("]")[0];
return Number(stringSize);

```

Output:

> ![Screenshot from 2024-08-10 17-22-44](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/d/8d3716caeba1dcaee85eb06b42b803355572a7b6.png)

Couldn’t get a numeric value out of it with Better logic, the result is a JSON, but the logic JSON extraction cards only accept string variables, not numeric ones  
 ![Screenshot from 2024-08-10 17-16-32](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/e/3e1d8220458715a45c772f87a4cc662e8b471971.png)

Source: [Mathjs.org](https://mathjs.org/docs/reference/functions/size.html)

---

<div class="post-metadata">

**Author:** ![Icepick](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/icepick/32/56463_2.png) [@Icepick](https://community.homey.app/u/Icepick)\
**Post date:** [August 11, 2024, 5:10am UTC](https://community.homey.app/t/can-the-length-of-a-string-be-calculated-in-a-flow/114159/4 "2024-08-11T05:10:53Z")

</div>

> [@Peter\_Kawa](#):
>
> ```auto
> // Filter the number out of the string size
> var response = args[0];
> const stringSize = '' + response.split("[")[1].split("]")[0];
> return Number(stringSize);
> 
> ```

Thanks so much.. this works great!
