任何.NET Parse方法都可以处理以“0x”为前缀的十六进制字符串吗? [英] Can any of the .NET Parse methods handle a hex string prefixed with "0x"?
问题描述
我尝试用.NET Int64.Parse方法解析一个数字,并且它不会接受像0x3039这样的字符串,尽管这就是您在C#中编写常量的方法。该文档特别禁止字符串具有0x前缀,并且后面的h似乎也不起作用。
I tried parsing a number with .NET Int64.Parse method, and it won't accept a string like "0x3039", even though that's how you write the constant in C#. The documentation specifically disallows the string to have a "0x" prefix, and a trailing "h" doesn't seem to work either.
要解析一个十六进制数,I必须使用 System.Globalization.NumberStyles.HexNumber
选项。
To parse a hexadecimal number, I must have to use the System.Globalization.NumberStyles.HexNumber
option.
如果有人知道离手, , Int64.Parse()
不能接受带有0x前缀的字符串,请告诉我。
If anyone knows off hand, for certain, that Int64.Parse()
cannot accept strings with a "0x" prefix, please let me know.
推荐答案
文档给出了表达式对于支持的数字格式,因此前缀和后缀都不允许用于十六进制数字。
The documentation gives the expressions for the supported number formats and accordingly neither prefixes nor postfixes are allowed for hexadecimal numbers.
Convert.ToInt32(String,Int32)
支持前缀 0x
和
0X
当使用基数16时。
Convert.ToInt32(String, Int32)
supports the prefixes 0x
and 0X
when using base 16.
这篇关于任何.NET Parse方法都可以处理以“0x”为前缀的十六进制字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!