Solved

AllowHexSpecifier doesn't parse "x1"

Posted on 2008-06-25
3
1,070 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

790 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