返回一个去掉源字符串首部和尾部的半角空格(半角space)的字符串

解决方案 »

  1.   

    你自己定义一个String a="Hello,That's    it is ."
    然后trim再输出看看不就可以了.
      

  2.   

    全部都说错了
    trim是去掉两边的white space
    所谓white space包括:
    '\t': tab
    '\n' '\r' '\f' 和 ' '
      

  3.   

    String  s="   I  am a student    ".trim();
    那么s是"I  am a student"。
      

  4.   

    晕,每人去度JDK文档啊,都说错了,是所有小于等于0x20的字符。
      

  5.   

    jimjxr(宝宝猫) ( ) 信誉:100  2004-03-27 14:23:00  得分:0 
     
     
      晕,每人去度JDK文档啊,都说错了,是所有小于等于0x20的字符。
      
     
    您老人家去看过jdk文档吗?
    还带个五角星呢?isSpace
    public static boolean isSpace(char ch)
    Deprecated. Replaced by isWhitespace(char). Determines if the specified character is ISO-LATIN-1 white space. This method returns true for the following five characters only: 
    '\t' '\u0009' HORIZONTAL TABULATION 
    '\n' '\u000A' NEW LINE 
    '\f' '\u000C' FORM FEED 
    '\r' '\u000D' CARRIAGE RETURN 
    ' ' '\u0020' SPACE 
      

  6.   

    不好意思是俺错了
    知错就该
    isWhitespace
    public static boolean isWhitespace(char ch)
    Determines if the specified character is white space according to Java. A character is a Java whitespace character if and only if it satisfies one of the following criteria: 
    It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F'). 
    It is '\u0009', HORIZONTAL TABULATION. 
    It is '\u000A', LINE FEED. 
    It is '\u000B', VERTICAL TABULATION. 
    It is '\u000C', FORM FEED. 
    It is '\u000D', CARRIAGE RETURN. 
    It is '\u001C', FILE SEPARATOR. 
    It is '\u001D', GROUP SEPARATOR. 
    It is '\u001E', RECORD SEPARATOR. 
    It is '\u001F', UNIT SEPARATOR. Parameters:
    ch - the character to be tested. 
    Returns:
    true if the character is a Java whitespace character; false otherwise.
    Since: 
    1.1 
    See Also:
    isSpaceChar(char)
      

  7.   

    Returns a copy of the string, with leading and trailing whitespace omitted.
      

  8.   

    trim
    public String trim()Returns a copy of the string, with leading and trailing whitespace omitted. 
    If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u0020' (the space character), then a reference to this String object is returned. Otherwise, if there is no character with a code greater than '\u0020' in the string, then a new String object representing an empty string is created and returned. Otherwise, let k be the index of the first character in the string whose code is greater than '\u0020', and let m be the index of the last character in the string whose code is greater than '\u0020'. A new String object is created, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m+1). This method may be used to trim whitespace from the beginning and end of a string; in fact, it trims all ASCII control characters as well. 
    Returns:
    A copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.--------------------------------------------------------------------------------