How to write in kotlin

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

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.

1 Like

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

1 Like