# How to find length of a String in a variable?

**URL:** <https://techcommunity.softwareag.com/t/how-to-find-length-of-a-string-in-a-variable/78487>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [July 6, 2008, 5:03pm UTC](https://techcommunity.softwareag.com/t/how-to-find-length-of-a-string-in-a-variable/78487 "2008-07-06T17:03:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jei1](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@Jei1](https://techcommunity.softwareag.com/u/Jei1)\
**Post date:** [July 6, 2008, 5:03pm UTC](https://techcommunity.softwareag.com/t/how-to-find-length-of-a-string-in-a-variable/78487/1 "2008-07-06T17:03:01Z")

</div>

Hi,

I want to find the length of a string in a char variable. The string can have a combination of numbers and alpha, even blanks.

I think we dont have a length function in Natural. Is there a way to find it, as a temp fix i am padding some pattern chars at the end of the string using COMPRESS and EXAMINE the position of pattern chars.

Thanks!!!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [July 6, 2008, 10:28pm UTC](https://techcommunity.softwareag.com/t/how-to-find-length-of-a-string-in-a-variable/78487/2 "2008-07-06T22:28:06Z")

</div>

```auto
define data local
 1 #string(A32) init<"abc 123 def">
 1 #len (I04)
end-define
*
examine full #string for ' ' giving length #len
write #len
*
end
```

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [July 7, 2008, 11:27am UTC](https://techcommunity.softwareag.com/t/how-to-find-length-of-a-string-in-a-variable/78487/3 "2008-07-07T11:27:32Z")

</div>

if you are reading the content from a file or otherwise have a dynamic variable, there is a length function:

```auto
define data 
local
 1 #string(A32) init<" abc 123 def"> 
 1 #dyn (A) dynamic
end-define 
*
compress #string into #dyn leaving no space
* or - *trim removes leading and trailing spaces...
#dyn := *trim(#string)
*
write *length(#dyn)
* 
end
```

---

<div class="post-metadata">

**Author:** ![Jei1](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@Jei1](https://techcommunity.softwareag.com/u/Jei1)\
**Post date:** [July 7, 2008, 5:08pm UTC](https://techcommunity.softwareag.com/t/how-to-find-length-of-a-string-in-a-variable/78487/4 "2008-07-07T17:08:56Z")

</div>

Thanks a lot for the replies. 😃

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [February 9, 2016, 5:23am UTC](https://techcommunity.softwareag.com/t/how-to-find-length-of-a-string-in-a-variable/78487/5 "2016-02-09T05:23:09Z")

</div>

we need to create Java service with above code and we have to use in flow service right …? dont mind for silly question , actually I am fresher trying for the same

Thank you

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:50pm UTC](https://techcommunity.softwareag.com/t/how-to-find-length-of-a-string-in-a-variable/78487/6 "2021-04-02T14:50:36Z")

</div>


