# How to write in kotlin

**URL:** <https://discuss.kotlinlang.org/t/how-to-write-in-kotlin/14698>\
**Category:** Support\
**Created:** [October 17, 2019, 2:33pm UTC](https://discuss.kotlinlang.org/t/how-to-write-in-kotlin/14698 "2019-10-17T14:33:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudeep.sager1234](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@sudeep.sager1234](https://discuss.kotlinlang.org/u/sudeep.sager1234)\
**Post date:** [October 17, 2019, 2:33pm UTC](https://discuss.kotlinlang.org/t/how-to-write-in-kotlin/14698/1 "2019-10-17T14:33:37Z")

</div>

in java  
while (pos1 \< len1 && (ch1 = str1.charAt(pos1++)) == ‘0’)  
{  
zeroes1++;  
}  
same i want to write in kotlin please help me

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [October 17, 2019, 3:14pm UTC](https://discuss.kotlinlang.org/t/how-to-write-in-kotlin/14698/2 "2019-10-17T15:14:34Z")

</div>

`zeroes1 = str1.indexOfFirst { It != '0' }`  
Does almost what you want. There is still the case in which all the string is a sequence of zeroes where this returns -1 and yours returns the length.

---

<div class="post-metadata">

**Author:** ![christofferberg79](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@christofferberg79](https://discuss.kotlinlang.org/u/christofferberg79)\
**Post date:** [October 17, 2019, 7:47pm UTC](https://discuss.kotlinlang.org/t/how-to-write-in-kotlin/14698/3 "2019-10-17T19:47:41Z")

</div>

`zeroes1 = str1.takeWhile { it == ’0’ }.length`
