java 中 String str=new String(); str.trim(); java中的string trim具体有什么用处。。。

string\u7684Trim()\u65b9\u6cd5\u662f\u505a\u4ec0\u4e48\u7684\uff1f

Java String.trim()\u65b9\u6cd5\u7528\u6cd5\u5b9e\u4f8b\u6559\u7a0b,\u8be5\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u590d\u5236\u8be5\u5b57\u7b26\u4e32\u7684\u5f00\u5934\u548c\u7ed3\u5c3e\u7684\u767d\u8272\u7a7a\u683c\u53bb\u6389\uff0c\u6216\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u5b83\u6ca1\u6709\u5934\u6216\u5c3e\u7a7a\u767d.
package com.yiibai;import java.lang.*;public class StringDemo { public static void main(String[] args) { // string with leading and trailing white space String str = " This is YiiBai "; System.out.print("Before trim = "); System.out.println(".." + str + ".."); // leading and trailing white space removed System.out.print("After trim = "); System.out.println(".." + str.trim() + ".."); }}

\u5c31\u662f\u628a\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u53ef\u80fd\u5b58\u5728\u7684\u9996\u5c3e\u7a7a\u683c\u53bb\u6389\u3002\u4f8b\u5982\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\u5982\u4e0b\uff1a

" 123456 abcefg "

\u90a3\u4e48\u7ecf\u8fc7trim()\u64cd\u4f5c\u5c31\u53d8\u6210\u4e86"123456 abcefg"
-------------------------------------------------------
\u6709\u65f6\u5019\u9700\u8981\u6821\u9a8c\uff0c\u5224\u65ad\u67d0\u4e2a\u5b57\u7b26\u4e32\u53d8\u91cf\u7684\u503c\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u8fd9\u4e2a\u201c\u7a7a\u201d\u7684\u610f\u601d\u4e0d\u5149\u662f\u6307null\uff0c\u8fd8\u6307empty(\u5c31\u662f\u5f62\u5982" "\u5168\u7a7a\u683c\u7684\u8fd9\u79cd\u503c)\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u7528trim()\u65b9\u6cd5\u628a\u9996\u5c3e\u7a7a\u683c\u53bb\u6389\uff0c\u7136\u540e\u518d\u5224\u65ad\u4e00\u4e0blength\u5c31\u77e5\u9053\u662f\u4e0d\u662fempty\u4e86\u3002

JS\u91cc\u9762\u4e5f\u6709\u8fd9\u4e2a\u51fd\u6570\uff0c\u529f\u80fd\u662f\u4e00\u6837\u7684\u3002

.trim()是取出前后空格。
比如:
abc ;就是去掉前面的跟后面的空格~

String str=new String();
str.trim();

trim()方法是去掉字符串前后的空格



新建一个String对象,然后去掉空格

去掉字符串后面的空格

扩展阅读:javascript 在线 ... java入门网站 ... java windowbuilder ... java char ... public static void main ... java compareto ... javascript入门 ... println ... java new string ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网