java中digit什么意思_Character.digit()的用法

1.在电话拨号盘PhoneNumberUtils.java有一段代码如下:/**

* Strips separators from a phone number string.

* @param phoneNumber phone number to strip.

* @return phone string stripped of separators.

*/

public static String stripSeparators(String phoneNumber) {

if (phoneNumber == null) {

return null;

}

int len = phoneNumber.length();

StringBuilder ret = new StringBuilder(len);

for (int i = 0; i < len; i++) {

char c = phoneNumber.charAt(i);

// Character.digit() supports ASCII and Unicode digits (fullwidth, Arabic-Indic, etc.)

int digit = Character.digit(c, 10);

if (digit != -1) {

ret.append(digit);

} else if (isNonSeparator(c)) {

ret.append(c);

}

}

return ret.toString();

}

其中有一个API是:

int digit = Character.digit(c, 10);

这个大概是把一个字符Char类型转化为一个整数.但是是转成什么样子了?

2.验证过程

官方的解释是:

public static int digit(char ch,int radix)

Returns the numeric value of the character ch in the specified radix.

If the radix is not in the range MIN_RADIX ≤ radix ≤ MAX_RADIX or if the value of ch is not a valid digit in the specified radix, -1 is returned. A character is a valid digit if at least one of the following is true:

The method isDigit is true of the character and the Unicode decimal digit value of the character (or its single-character decomposition) is less than the specified radix. In this case the decimal digit value is returned.

The character is one of the uppercase Latin letters 'A' through 'Z' and its code is less than radix + 'A' - 10. In this case, ch - 'A' + 10 is returned.

The character is one of the lowercase Latin letters 'a' through 'z' and its code is less than radix + 'a' - 10. In this case, ch - 'a' + 10 is returned.

The character is one of the fullwidth uppercase Latin letters A ('\uFF21') through Z ('\uFF3A') and its code is less than radix + '\uFF21' - 10. In this case, ch - '\uFF21' + 10 is returned.

The character is one of the fullwidth lowercase Latin letters a ('\uFF41') through z ('\uFF5A') and its code is less than radix + '\uFF41' - 10. In this case, ch - '\uFF41' + 10 is returned.

Note: This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the digit(int, int) method.

Parameters:

ch - the character to be converted.

radix - the radix.

Returns:

the numeric value represented by the character in the specified radix.

See Also:

forDigit(int, int), isDigit(char)

大概猜出了是把字符类型转化为radix进制的整数.比如radix为10就转为10进制的,16就是16进制的.如果该字符不是进制内的就返回-1.

验证的代码如下:

package Say;

public class Diagi {

public static void main(String[] args) {

char num1 = '0';

char num2 = '9';

char a = 'A';

char as = 'a';

char f = 'F';

char fs = 'f';

System.out.println("result:" + Character.digit(num1, 16));

System.out.println("result:" + Character.digit(num2, 16));

System.out.println("result:" + Character.digit(a, 16));

System.out.println("result:" + Character.digit(as, 16));

System.out.println("result:" + Character.digit(f, 16));

System.out.println("result:" + Character.digit(fs, 16));

System.out.println("result:" + Character.digit('H', 16));

}

}

结果如下:

result:0

result:9

result:10

result:10

result:15

result:15

result:-1

验证的结果也证实了猜测.

3.stripSeparator函数的意思

该函数是把拨号盘输入的字符,格式化成10进制数,如果有字母将会被忽略掉.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
华新水泥股份有限公司技术管理心 TECHNOLOGY MANAGEMENT CENTER, HUAXIN CEMENT CO. , LTD. WINCC 服务器/客户端的配置 服务器(冗余服务器)的配置 客户端的配置 时间同步设置 图形界面的设定于相关属性 1 华新水泥股份有限公司技术管理心 TECHNOLOGY MANAGEMENT CENTER, HUAXIN CEMENT CO. , LTD. 服务器(冗余服务器)的设置 Project Properties 对于每一个OS项目打开后首先我们可以通过点击他的属性来设置一些参数。在 General项我们可以看见这个项目的类型等一些信息,这里不需要修改。对于服务 器来说,它属于"Multi-User Project"。在"Update Cycles"栏,我们可以根据自身的需 求来设定我们所需的时间,而默认设置为2000ms,CEMAT通常使用"User Cycle 1" 或 者 "Anwenderzyklus 1"。(图24) 图24 2 华新水泥股份有限公司技术管理心 TECHNOLOGY MANAGEMENT CENTER, HUAXIN CEMENT CO. , LTD. OS Project Properties Editor 我们使用OS Project Properties Editor 来确定显示界面的大小,通常我们的分辨率 都选择1280*1024。 图25 3 华新水泥股份有限公司技术管理心 TECHNOLOGY MANAGEMENT CENTER, HUAXIN CEMENT CO. , LTD. Computer Properties 我们必须在startup下的Additional Tasks/Applications添加CEMAT启动项 Scan_CS.exe,它放在目录D:\CEM_V6\BIN下。 图26 4 华新水泥股份有限公司技术管理心 TECHNOLOGY MANAGEMENT CENTER, HUAXIN CEMENT CO. , LTD. Tag Management 打开Tag Management添加组CEMAT,并且在其添加如下变量,其如果用户使 用的是6.0版本那么需要添加所有变量,如果使用的是6.1版本,那么就只需要添加前3 个。 Name Data Type Name update C_VIEW_TAG_A Binary Computer-local update C_VIEW_TAG_D Binary Computer-local update C_ServerName Text tag 16bit Computer-local update C_AcknowledgeHorn Unsigned 32-Bit Value Project-wide update C_<ComputerName>_AlarmSound Singed 16-Bit Value Computer-local update 如果我们需要使用声音报警,那么我们就还需要添加组Horn并在其下面添加如下变 量,如果我们需要在客户端使用声音报警确认,那么我们还必须在客户端的Horn configuration配置它。 Name Data Type Name update HornResetMC binary Project-wide 添加组Redundancy,并在其添加如下变量,不论我们是否使用冗余服务器,我们 都需要他们。 Name Data Type Name update @RM_MASTER Binary Project-wide @RM_MASTER_NAME Text tag 8bit character set Project-wide @RM_SERVER_NAME Text tag 8bit character set Project-wide @RM_OFFLINE_UA_NAME Text tag 8bit character set Project-wide General change in the alarm logging 双击打开 "Alarm Logging" 做出如下修改: Date Four-Digit Day.Month.Year System blocks Time H/M/S (不要选择 Milliseconds) Origin Source 改为 Tag Length = 22 Flashing = off Event Length = 20 Flashing = off Free 1 Free 1 改为 Tag Comment Length = 42 User text block

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值