当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Character isISOControl()用法及代码示例


Character 类的 isISOControl(int codePoint) 方法一般判断引用的字符是否为 ISO 控制字符。

如果给定字符的代码在 '\u000' 到 '\u001F' 的范围内或在 '\u007F' 到 '\u009F' 的范围内,则可以将字符视为 ISO 控制字符。

用法

public static boolean isISOControl(int codePoint)

参数

codePoint:codePoint 是需要测试的字符。

返回值

如果给定(或指定)字符是 ISO 控制字符,则 isISOControl(int codePoint) 方法返回一个布尔值,即 true。否则,该方法返回 false

例子1

public class JavaCharacterisISOControlExample_1 {
public static void main(String args[]){
	// Initialize three codepoints.
	   int codepoint1 = 28;
	   int codepoint2 = 13480;
	   int codepoint3 = 13542;
	// Check whether the codepoints are isISOControl character or not.
	   boolean check1 = Character.isISOControl(codepoint1);
	   boolean check2 = Character.isISOControl(codepoint2);
	   boolean check3 = Character.isISOControl(codepoint3);
	// Print the result.
	
System.err.print("The first codepoint \'"+codepoint1+"\' is an ISO Control:"+check1+ "\n");
System.err.print("The second codepoint \'"+codepoint2+"\' is an ISO Control:"+check2+"\n");	
System.err.print("The third codepoint \'"+codepoint3+"\' is  an ISO Control:"+check3+"\n");		
   }
}

输出:

The first codepoint '28' is an ISO Control:true
The second codepoint '13480' is an ISO Control:false
The third codepoint '13542' is  an ISO Control:false

例子2

import java.util.Scanner;
public class JavaCharacterisISOControlExample_2 {
    public static void main(String[] args) {
    // Ask for user input
       System.out.print("Enter the first input:");
    // Use the Scanner class to get the user input
       Scanner s1 = new Scanner(System.in);
    // Gets the user input
       char[] value1 = s1.nextLine().toCharArray();
    // Check whether the user input is an ISO control character or not
       for (char ch1:value1) {
boolean result1 = Character.isISOControl(ch1);
    // print the result
if(result1){
System.out.println("The character " + ch1 + " is an ISO control character:");				
}
else{
System.out.println("The character " + ch1 + " is not an ISO control character:");
           }		
System.out.print("Enter the second input:");
       Scanner s2 = new Scanner(System.in);
       char[] value2 = s2.nextLine().toCharArray();
       for (char ch2:value2) {
boolean result2 = Character.isISOControl(ch2);
if(result2){
System.out.println("The character " + ch2 + " is an ISO control character:");				
}
else{
System.out.println("The character " + ch2 + " is not an ISO control character:");
        }		
      }
    }
  }
}

输出:

Enter the first input:@
The character @ is not an ISO control character:
Enter the second input:A
The character A is not an ISO control character:




相关用法


注:本文由纯净天空筛选整理自 Java Character isISOControl() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。