0

I'm trying to convert a number into digits and save in an Array using VBScript.

For instance, if i have a number '5508426' then I want to make that as

A[0] = '5'
A[1] = '5'
A[2] = '0'
A[3] = '8'
A[4] = '4'
A[5] = '2'
A[6] = '6'

Can anyone help me in this, please?

1 Answer 1

4

Create a suitable sized array and fill it with the digits obtained by Mid():

>> s = "5508426"
>> ReDim a(Len(s) - 1)
>> For i = 0 To UBound(a)
>>     a(i) = Mid(s, i + 1, 1)
>> Next
>> WScript.Echo Join(a, "-")
>>
5-5-0-8-4-2-6

You may think about data types - strings vs. numbers - determine what you have as input and what you want as elements, and then throw in some CStr() and/or CInt()/CLng()/CDbl().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.