By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

Convert srting "(192)"

P: n/a
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
Jul 22 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
using System.Globalization;

string num = "(192)";
int foo = int.Parse(num, NumberStyles.AllowParentheses);
Console.WriteLine(foo);

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Robert Bravery" <me@u.comwrote in message
news:Ov**************@TK2MSFTNGP03.phx.gbl...
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


Jul 22 '06 #2

P: n/a
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(&lt;your_string&gt;)

RBHI all,
RB>
RBI have imported string data that contains numerical values. The
RBnegatives are reporesented in round braces () as in (192)
RBrepresenting -192. How can I convert thin string into a negative
RBnumber while converting other numbers as positive numerical data
RB>
RBThanks
RBRobert
---
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
Jul 22 '06 #3

P: n/a
Thanks All

Robert

"Robert Bravery" <me@u.comwrote in message
news:Ov**************@TK2MSFTNGP03.phx.gbl...
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


Jul 22 '06 #4

P: n/a
Hello Greg,

Gotcha! it catched from my mind

GYusing System.Globalization;
GY>
GYstring num = "(192)";
GYint foo = int.Parse(num, NumberStyles.AllowParentheses);
GYConsole.WriteLine(foo);
GYCheers,
GY>
GYGreg Young
GYMVP - C#
GYhttp://codebetter.com/blogs/gregyoung
GY"Robert Bravery" <me@u.comwrote in message
GYnews:Ov**************@TK2MSFTNGP03.phx.gbl...
GY>
>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
---
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
Jul 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.