I'm going on the assumption here that the string you're trying to parse is an actual currency value.
I'm going on the assumption here that the string you're trying to parse is an actual currency value. CultureInfo c = CultureInfo. CreateSpecificCulture(CultureInfo.CurrentCulture.Name); c.NumberFormat.
CurrencyNegativePattern = 14; // From MSDN -- no enum values for this c.NumberFormat. CurrencySymbol = "USD"; decimal d = Decimal. Parse("(USD 92.90)", NumberStyles.
Currency, c).
1 +1, I didn't know about passing the NumberStyles. I'd still use TryParse though (I notice it takes the same parameters)... – Philip Wallace Oct 28 '09 at 12:52 I like this. Although what if the Currency changes?
– LB. Oct 28 '09 at 12:57 1 @LB: If you're dealing with multiple currencies, I'd parse them each one at a time. Since the values themselves aren't really comparable to each other (i.e.
, USD$15! = CAD$15), it's somewhat meaningless to put all of them in a single array, for example. – Jon Seigel Oct 28 '09 at 13:01 You're right.
Thanks Jon! – LB. Oct 28 '09 at 13:05.
You could start off with a reg-exp to extract the number part and then use Decimal. TryParse to parse the sub-string.
First, get the number out of the string. A Regex \d+(.\d+)? Might help there.
Although you could use substring, if the characters around that number are always the same. Then use Decimal. Parse (or Double.
Parse) on that string.
When parsing strings, I always prefer to use TryParse to avoid exceptions being thrown for invalid strings: string str = "(USD 92.90)"; decimal result; if (Decimal. TryParse(str, out result)) { // the parse worked } else { // Invalid string } And as others have said, first use a regular expression to extract just the numerical part.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.