Integer to array conversion


#1

Hi…

I am trying to convert a string to integer and trying to save it in an array of integers.

Pages = Integer.Parse(page_count.Substring(7,2))

Note: Pages should be of type Int32[].
I am getting an error as a value of type integer cannot be converted to a 1-dimensional array.

Can anyone please help me to figure this out.


#2

Hi Sarigam,

You need to do the following steps, right?
String --> Integer
Integer --> one value of Int32[]

If so, please refer to the prototype of this solution

Hope this helps!
Thanks


#3

Hi,

It was throwing error because Integer.Parse(page_count.Substring(7,2)) returns a Integer value.
But Pages is an array variable. So the place where the integer has to be stored must be mentioned like Pages(0) or Pages(i) where i can be declared as a counter variable.

Thanks


#4

Hi @Sarigam,

Alongwith the clear and detailed explanation from SaranyaKishore, We can also use a one line conversion.

Assumption:

String Page_count = "123456"

Code Snippet:

int[] intArray = Page_count.Substring(1,2).Select(Function(x) Val(x)).ToArray()

Explanation:

Getting two chars as a string and selecting the individual characters of string i.e here 2 and 3 & using Microsoft.VisualBasic.Val to get only the values and parse as integers
Microsoft.VisualBasic.Asc to get only the ASCII values and parse as integers

Regards,
Dom :slight_smile:


#5

Thank you for your prompt response.

Let me explain more detail on it.
String Page_count = “24 items in 3 pages”

I have to store the value “3” to variable type of integer array Pages in the above string.

then I have to use the Pages in For each activity

I tried the above example and still am not getting the desired output.


#6


#7

Sariga, Let me confirm my understanding !

String Page_count = “24 items in 3 pages”
  1. From the above string, Do you want to extract 3 alone ? or all the numbers 24 and 3 ?
  2. Do you want to loop that many number of times ? (Here 3 times)

#8

Just to extract 3 alone.
Yes, I want to loop that many number of times


#9

Hi @sarigam,
You I have attached the source for the page loop. it helps you.

File : PageLoop.zip (2.2 KB)

Regards
Balamurugan


#10

Thank you Balamurugan.
I need to use For each Activity not the do while for some reasons


#11

Hi @sarigam,
I did the changes now. It will have the loop by for.

File : PageLoop.zip (2.3 KB)

Regards
Balamurugan


#12

I tried the same. But receving error as Input string is not in correct format


#13

Hi @sarigam,
Did you get error in my sample project ? or the implemented one ?

Regards
Balamurugan


#14

On the implemented one…


#15


#16

Hi @sarigam,
Can you check the variable declarations.

The for loop activity should be like this
image

Regards
Balamurugan