Can Convert.Int32 handle Thousands separator?

  • Thread starter Thread starter Tim Osborne
  • Start date Start date
T

Tim Osborne

I want to know if a call to Convert.Int32 can handle a Culture specific
string.

I have the following code:

string sText = "111,111,111";
int i;

i = Convert.Int32( sText );

This throws an exception.

So I try adding the following:

CultureInfo ci = Thread.CurrentThread.CurrentCulture;

i = Convert.Int32( sText, ci.NumericInfo );

This also throws.

Do I have to remove the Thousands Separator character myself?
 
Hi Tim,

Suggest:

string sText = "111,111,111";
int i;

i = Int32.Parse(sText, NumberStyles.AllowThousands);

Regards,
Dan
 
Tim,

On the culture you are using, check the NumberFormat property. On the
NumberFormatInfo instance returned, check the NumberGroupSeparator property
to see the character used to separate groups.

Hope this helps.
 
I got there about the same time as you did.

Actually I went with NumberStyles.Number.

Thanks a lot for the quick response though.
 
Back
Top