# sequence number of a character

## Recommended Posts

Hi, i need some help. How can I get the sequence number of the "0"s here.

\$string = "17000220064602"

I'm trying to reach this  >>>< 3 - 4 - 5 - 8 - 9 - 13

##### Share on other sites

One way to do it would be to split the char string into an array of chars (StringSplit).  Then, spin through the array of chars looking for the char of interest.

Spoiler
```example()

Func example()
Const \$CHAR_STRING = "17000220064602"

Local \$aChars = StringSplit(\$CHAR_STRING, "") ;Split char string into array of chars

;For each char in the array
For \$i = 1 To \$aChars[0]
If \$aChars[\$i] = "0" Then ConsoleWrite("Char found at position " & \$i & @CRLF)
Next
EndFunc```

Console output:

```Char found at position 3
Char found at position 4
Char found at position 5
Char found at position 8
Char found at position 9
Char found at position 13```

Edited by TheXman
Fixed For/Next loop

"Any fool can know.  The point is to understand."  -Albert Einstein

##### Share on other sites

1 hour ago, TheXman said:

One way to do it would be to split the char string into an array of chars (StringSplit).  Then, spin through the array of chars looking for the char of interest.

Reveal hidden contents
```example()

Func example()
Const \$NUMBER_SEQUENCE = "17000220064602"

Local \$aChars = StringSplit(\$NUMBER_SEQUENCE, "") ;Split char string into array of chars

;For each char in the array
For \$i = 0 To \$aChars[0]
If \$aChars[\$i] = "0" Then ConsoleWrite("Char found at position " & \$i & @CRLF)
Next
EndFunc```

Console output:

```Char found at position 3
Char found at position 4
Char found at position 5
Char found at position 8
Char found at position 9
Char found at position 13```

I tried with StringSplit but couldn't it. I could only reach the first 0 😢

Edited by mixim
##### Share on other sites

Click on "Reveal hidden contents" in my previous post.

And next time, don't say what didn't work without showing it.

Edited by TheXman

"Any fool can know.  The point is to understand."  -Albert Einstein

##### Share on other sites

... or also by scanning each char of the string using string functions

```\$sString = "17000220064602"

For \$i = 1 To StringLen(\$sString)
If StringMid(\$sString, \$i, 1) = "0" Then ConsoleWrite(\$i & " - ")
Next```

Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

##### Share on other sites

@TheXman ok, i got it

I thank you very much friends. These helped me.❤️

##### Share on other sites

You could also use _ArrayFindAll

```#include <Array.au3>

\$sString = "17000220064602"
\$aString = StringSplit(\$sString, "", 1)
\$aResult = _ArrayFindAll(\$aString, "0")
_ArrayDisplay(\$aResult)```

##### Share on other sites

@subz gets the trophy, everybody else gets the love

Code hard, but don’t hard code...

##### Share on other sites

18 minutes ago, JockoDundee said:

@subz gets the trophy, everybody else gets the love

## Some people will be honoured, others will be adored.

(I hope this pun will not get lost in translation)

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

## Create an account

Register a new account