sarigam
(Sariga)
May 9, 2018, 7:22am
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.
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
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
Dominic
(Dominic)
May 9, 2018, 8:15am
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
sarigam
(Sariga)
May 9, 2018, 8:25am
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.
Dominic
(Dominic)
May 9, 2018, 8:30am
7
Sariga, Let me confirm my understanding !
String Page_count = “24 items in 3 pages”
From the above string, Do you want to extract 3 alone ? or all the numbers 24 and 3 ?
Do you want to loop that many number of times ? (Here 3 times)
sarigam
(Sariga)
May 9, 2018, 9:07am
8
Just to extract 3 alone.
Yes, I want to loop that many number of times
balupad14
(Balamurugan (BalaReva))
May 9, 2018, 9:15am
9
Hi @sarigam ,
You I have attached the source for the page loop. it helps you.
File : PageLoop.zip (2.2 KB)
Regards
Balamurugan
sarigam
(Sariga)
May 9, 2018, 9:17am
10
Thank you Balamurugan.
I need to use For each Activity not the do while for some reasons
balupad14
(Balamurugan (BalaReva))
May 9, 2018, 9:27am
11
Hi @sarigam ,
I did the changes now. It will have the loop by for.
File : PageLoop.zip (2.3 KB)
Regards
Balamurugan
sarigam
(Sariga)
May 9, 2018, 11:15am
12
I tried the same. But receving error as Input string is not in correct format
balupad14
(Balamurugan (BalaReva))
May 9, 2018, 11:17am
13
Hi @sarigam ,
Did you get error in my sample project ? or the implemented one ?
Regards
Balamurugan
balupad14
(Balamurugan (BalaReva))
May 9, 2018, 12:07pm
16
Hi @sarigam ,
Can you check the variable declarations.
The for loop activity should be like this
Regards
Balamurugan