i have serious problem c#, code:
string pricelowstring = inventory.exportprice(price.lowest_price); string pricestring = inventory.exportprice(price.median_price); log.success(pricelowstring); log.success(pricestring); int priceavg = int.parse(pricestring); int pricelow = int.parse(pricelowstring);
and receive error:
[gicminos 2016-08-01 11:52:56] success: 4 [gicminos 2016-08-01 11:52:56] success: 2 [gicminos 2016-08-01 11:52:56] error: unhandled exception occurred in bot: system.formatexception: input string not in correct format. @ system.number.stringtonumber(string str, numberstyles options, numberbuffer& number, numberformatinfo info, boolean parsedecimal) @ system.number.parseint32(string s, numberstyles style, numberformatinfo info) ....
as can see on log message, strings correct , don't have spaces..
i checked /hkey_current_user/control panel/international/spositivesign
, it's blank.
what have resolve problem?
i assume got hidden characters there. can remove characters not digits:
pricestring = new string(pricestring.where(c => char.isdigit(c)).toarray());
this fail in case have fraction number - in case want parse int.
also - try , use tryparse
instead of parse
- safer way
Comments
Post a Comment