检查十六进制字符串只包含十六进制有界值 [英] check hex string contains only hex bounded values

查看:166
本文介绍了检查十六进制字符串只包含十六进制有界值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查给定的十六进制字符串只包含十六进制数字。是否有任何简单的方法或任何Java库的相同?我有字符串像01AF,我必须检查字符串只包含十六进制范围值,因为我现在正在做的是采取字符串,然后拆分字符串和然后将其转换为适当的格式,然后检查该值。有没有简单的方法呢?

How to check a given hex string contains only hex number. is there is any simple method or any java library for the same?i have string like "01AF" and i have to check string only contains hex range values,for that what i am doing now is take the string and then split the string and then converted it to appropriate format then make a check for that value.is there is any simple method for that?

推荐答案

try
{
    String hex = "AAA"
    int value = Integer.parseInt(hex, 16);  
    System.out.println("valid hex);
 }
 catch(NumberFormatException nfe)
 {
    // not a valid hex
    System.out.println("not a valid hex);
 }

如果十六进制字符串无效,将抛出NumberFormatException。

This will throw NumberFormatException if the hex string is invalid.

请参阅文档这里

这篇关于检查十六进制字符串只包含十六进制有界值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆