Solved

AllowHexSpecifier doesn't parse "x1"

Posted on 2008-06-25
3
1,040 Views
Last Modified: 2008-07-03
I'd like to parse
      int a = Int32.Parse("x1",System.Globalization.NumberStyles.AllowHexSpecifier);
but it throws FormatException "Input string was not in a correct format."

What should I be doing?
0
Comment
Question by:josgood
3 Comments
 
LVL 14

Expert Comment

by:rachitkohli
ID: 21871958
If you want to specify hex specified, its &H
example CLng("&H12")

Else in case of your function it should be just 1 & not x1
0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21871970
What about this:
"0x1"
0
 
LVL 13

Accepted Solution

by:
josgood earned 0 total points
ID: 21871992
Actually, I just figured it out.

Silly me (silly us) we were thinking that there would be an 'H' or an 'X' in the string.  Little do we know!  Urgh.

From http://msdn.microsoft.com/en-us/library/system.globalization.numberstyles(VS.80).aspx
"Indicates that the numeric string represents a hexadecimal value. Valid hexadecimal values include the numeric digits 0-9 and the hexadecimal digits A-F and a-f. Hexadecimal values can be left-padded with zeros. Strings parsed using this style are not permitted to be prefixed with "0x". "

I was thinking that the leading zero was disallowed.  The leading 'X' is also disallowed.

That is *really* surprising.

If the user is astonished, which I am, then the design is bad.

Thank you guys.  I appreciate you trying.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now