Java Character isISOControl()方法及实例
java.lang.Character.isISOControl() 是java中的一个内置方法,用于确定指定的字符是否是ISO控制字符。如果一个字符的代码在’\u0000’到’\u001F’的范围内或在’\u007F’到’\u009F’的范围内,则被认为是一个ISO控制字符。这种方法不能处理补充字符。为了支持所有的Unicode字符,包括补充字符,上述方法中的参数可以是int数据类型。
语法
public static boolean isISOControl(data_type ch)
参数: 该函数接受一个参数 ch ,这是必须的。它指定了要测试的字符。该参数可以是char或int数据类型。
返回值: 该函数返回一个布尔值。如果该字符是ISO控制字符,该布尔值为真,否则为假。
下面的程序说明了上述方法。
程序1 :
// java program to demonstrate
// Character.isISOControl() method
// when the parameter is a character
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// create 2 char primitives c1, c2 and assign values
char c1 = '-', c2 = '\u0017';
// assign isISOControl results of c1
// to boolean primitives bool1
boolean bool1 = Character.isISOControl(c1);
if (bool1)
System.out.println(c1 + " is an ISO control character");
else
System.out.println(c1 + " is not an ISO control character");
// assign isISOControl results of c2
// to boolean primitives bool2
boolean bool2 = Character.isISOControl(c2);
if (bool2)
System.out.println(c2 + " is an ISO control character");
else
System.out.println(c2 + " is not an ISO control character");
}
}
输出:
- is not an ISO control character
is an ISO control character
程序2
// java program to demonstrate
// Character.isISOControl(char ch) method
// when the parameter is an integer
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// create 2 char primitives c1, c2 and assign values
int c1 = 0x008f;
int c2 = 0x0123;
// assign isISOControl results of c1
// to boolean primitives bool1
boolean bool1 = Character.isISOControl(c1);
if (bool1)
System.out.println(c1 + " is an ISO control character");
else
System.out.println(c1 + " is not an ISO control character");
// assign isISOControl results of c2
// to boolean primitives bool2
boolean bool2 = Character.isISOControl(c2);
if (bool2)
System.out.println(c2 + " is an ISO control character");
else
System.out.println(c2 + " is not an ISO control character");
}
}
输出:
143 is an ISO control character
291 is not an ISO control character
参考资料 : https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isISOControl(char)