Array of string conversion

I have extracted some fields from text file using string manipulation and those are in 1-D string type.I am trying to convert array of string into integer as i want to add those numbers. Every time when i use the convert function it gives the error “Input string was not in correct format”.
Can anyone suggest the solution?

1 Like

Hi!
Can you show us a sample of the text file?
Thank you :slight_smile:

1 Like

Hi @KeertiJ,
Probably you have some non digit signs in your variable after conversion so it can’t be converted to integer. As @Jan_Brian_Despi said please show us example of it so hopefully we will be able to help you with this.

1 Like

Hello There,

Kindly let us know that you want to convert string array to integer array.
Am I right?
if so use below code to do that,

int intArr = Array.ConvertAll(strArr, int.Parse)

Cheers,
Pankaj

@Jan_Brian_Despi @Pablito I have extracted the Tax and Subtotal field and then removed the $ symbol,now want to add these 2 numbers.Both these are in the form of str.CRA.zip (533 Bytes)

1 Like

@Pankaj.Patil i want to convert the string array to integer.

Use CInt(variableName)

1 Like

This solution is working. but it is rounding off the figure. I mean if the string array is 123.88 it converts into int and takes the value 124.

1 Like

Hi @KeertiJ

Use Convert.ToDouble(variable) instead.

Thanks :slight_smile:

2 Likes

Hello There,

Please follow up below picture,

String%20Array%20to%20Int%20Conversion

Desc : 1) made a string array var,
2) Iterated it and assigned each to value to int var
3) printed in msg box.

Please let us know if this works for you.

Cheers,
Pankaj

How was it? :slight_smile:

1 Like

Thank you. It works.

1 Like

Good! Please mark the answer as the solution. Thank you! :slight_smile:

1 Like

Yes it works for non decimal integers.
Thank you.

1 Like

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