Foreach numbersucesion

Hola, favor su ayuda , tengo un numero variable Ejemplo “5.544.332” debo recorrelo de derecha a izquierda, multiplicando cada dígito por los números que componen la serie numérica 2, 3, 4, 5, 6, y 7. Ayuda?

Hello, please help, I have a variable number. Example “5,544,332” I must go through it from right to left, multiplying each digit by the numbers that make up the numerical series 2, 3, 4, 5, 6, and 7. Help?

Duplicated post

@JulioCesar1988
try this vb.net code:

Dim originalNumber As String = "5,544,332"
Dim cleanNumber As String = originalNumber.Replace(",", "")
Dim numberArray As Char() = cleanNumber.ToCharArray()
Array.Reverse(numberArray)
Dim series As Integer() = {2, 3, 4, 5, 6, 7}
Dim results As New List(Of Integer)

For i As Integer = 0 To numberArray.Length - 1
    Dim digit As Integer = Int32.Parse(numberArray(i).ToString())
    results.Add(digit * series(i Mod series.Length))
Next

Result - List(7) { 4, 9, 12, 20, 24, 35, 10 }
“5544332”, reversed to “2334455”, and then applying the multiplication:

  1. 2 * 2 = 4
  2. 3 * 3 = 9
  3. 3 * 4 = 12
  4. 4 * 5 = 20
  5. 4 * 6 = 24
  6. 5 * 7 = 35
  7. 5 * 2 = 10

Please delete duplicated post:

Im sorry, but im new uith this, how to invoke VB code ???

Hi,

The following post may help you.

Regards,

Hi @JulioCesar1988

Try this way:

Assign-> number = "5,544,332"

Assign-> multipliers = {2, 3, 4, 5, 6, 7}

Assign-> result = String.Join(vbCrLf,number.Replace(",", "").
                  Reverse().
                  Select(Function(digit, index) Convert.ToInt32(digit.ToString()) * multipliers(index Mod multipliers.Length)).
                  ToList())

number is of DataType System.String. multipliers is of DataType Array(System.Int32). result is of DataType System.String.

Or

Assign-> number = "5,544,332"

Assign-> multipliers = {2, 3, 4, 5, 6, 7}

Assign-> result = String.Join(vbcrlf,Enumerable.Range(0, number.Replace(",", "").Reverse().ToArray().Length).
                           Select(Function(i) $"{number.Replace(",", "").Reverse().ToArray()(i)} * {multipliers(i Mod multipliers.Length)} = {Convert.ToInt32(number.Replace(",", "").Reverse().ToArray()(i).ToString()) * multipliers(i Mod multipliers.Length)}").
                           ToList())

Both the queries should work

Hope it helps!!

@JulioCesar1988
here is a project how to use this:
BlankProcess114.zip (3.1 KB)

1 Like

Thank you!!! your solution helped me a lot!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.