📜  带有Java示例的字符.isISOControl() 方法

📅  最后修改于: 2022-05-13 01:55:02.069000             🧑  作者: Mango

带有Java示例的字符.isISOControl() 方法

Java.lang。 字符.isISOControl()是Java中的内置方法,用于确定指定字符是否为 ISO 控制字符。如果字符的代码在 '\u0000' 到 '\u001F' 范围内或在 '\u007F' 到 '\u009F' 范围内,则该字符被视为 ISO 控制字符。此方法无法处理补充字符。为了支持所有 Unicode字符,包括增补字符,上述方法中的参数可以是 int 数据类型。

句法:

public static boolean isISOControl(data_type ch)

参数:该函数接受一个强制的参数ch 。它指定要测试的字符。参数可以是 char 或 int 数据类型。

返回值:函数返回一个布尔值。如果字符是 ISO 控制字符,则布尔值为 true,否则为 false。

下面的程序说明了上述方法:

方案一:

// 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

方案二:

// 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: Java/lang/ 字符.html#isISOControl(char)