Convert srting "(192)"

  • Thread starter Thread starter Robert Bravery
  • Start date Start date
R

Robert Bravery

HI all,

I have imported string data that contains numerical values. The negatives
are reporesented in round braces () as in (192) representing -192. How can I
convert thin string into a negative number while converting other numbers as
positive numerical data

Thanks
Robert
 
Hello Robert,

There are a lot of variations - regexp, checking "(" existence and etc
Smth like using String.Replace to replace the "(" on "-", remove "-" and
Convert.ToInt32(<your_string>)

RB> HI all,
RB>
RB> I have imported string data that contains numerical values. The
RB> negatives are reporesented in round braces () as in (192)
RB> representing -192. How can I convert thin string into a negative
RB> number while converting other numbers as positive numerical data
RB>
RB> Thanks
RB> Robert
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Hello Greg,

Gotcha! it catched from my mind

GY> using System.Globalization;
GY>
GY> string num = "(192)";
GY> int foo = int.Parse(num, NumberStyles.AllowParentheses);
GY> Console.WriteLine(foo);
GY> Cheers,
GY>
GY> Greg Young
GY> MVP - C#
GY> http://codebetter.com/blogs/gregyoung
GY> GY>---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
Back
Top