Solved

AllowHexSpecifier doesn't parse "x1"

Posted on 2008-06-25
3
1,076 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net/VSTO Excel Add-in 2 18
C# Windows Form Navigation - Total Beginner 9 48
Return array 3 20
Inserting LocalDB Table to SQL Server C# 3 19
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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…

733 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