性格isISOControl()方法及其Java示例

这个 JAVA朗,性格。isISOControl() 是java中的内置方法,用于确定指定字符是否为ISO控制字符。如果一个字符的代码在“u0000”到“u001F”之间,或在“u007F”到“u009F”之间,则该字符被视为ISO控制字符。此方法无法处理补充字符。为了支持所有Unicode字符,包括补充字符,在上述方法中,参数可以是int数据类型。

null

语法:

public static boolean isISOControl(data_type ch)

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

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

以下程序说明了上述方法:

项目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(字符)

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享