{"id":2748,"date":"2023-04-12T17:21:45","date_gmt":"2023-04-12T09:21:45","guid":{"rendered":"https:\/\/hsin-life.com\/?p=2748"},"modified":"2023-04-12T17:21:47","modified_gmt":"2023-04-12T09:21:47","slug":"%e6%b7%b1%e5%85%a5%e7%90%86%e8%a7%a3java%e4%b8%ad%e7%9a%84trim%e6%96%b9%e6%b3%95%e5%8f%8a%e5%85%b6%e8%ae%8a%e9%ab%94","status":"publish","type":"post","link":"https:\/\/hsin-life.com\/archives\/2748","title":{"rendered":"\u6df1\u5165\u7406\u89e3Java\u4e2d\u7684trim\u65b9\u6cd5\u53ca\u5176\u8b8a\u9ad4"},"content":{"rendered":"\n
Java\u4e2d\u7684trim\u65b9\u6cd5\u7528\u65bc\u53bb\u9664\u5b57\u7b26\u4e32\u5169\u908a\u7684\u7a7a\u683c\u6216\u5236\u8868\u7b26\uff0c\u800ctrimToEmpty\u548ctrimToNull\u662ftrim\u65b9\u6cd5\u7684\u8b8a\u9ad4\u3002<\/p>\n\n\n\n
\u4ee5\u4e0b\u5c07\u5c0d\u9019\u4e09\u500b\u65b9\u6cd5\u7684\u6e90\u78bc\u9032\u884c\u89e3\u6790\u3002<\/p>\n\n\n\n
public static String trim(String str) {\r\nreturn str == null ? null : str.trim();\r\n}<\/code><\/pre>\n\n\n\n\u6e90\u78bc\u89e3\u6790\uff1a\u5982\u679c\u8f38\u5165\u7684\u5b57\u7b26\u4e32\u70banull\uff0c\u5247\u8fd4\u56denull\uff1b\u5426\u5247\u53bb\u9664\u6389\u5b57\u7b26\u4e32\u5169\u908a\u7684\u7a7a\u683c\u6216\u8005\u5236\u8868\u7b26\uff08tab\u9375\uff0c\u4e00\u500btab\u9375\u4ee3\u8868\u5169\u500b\u7a7a\u683c\uff09\u3002<\/p>\n\n\n\n
\n- trimToEmpty\u65b9\u6cd5\u6e90\u78bc\u8a73\u89e3\uff1a<\/li>\n<\/ul>\n\n\n\n
public static String trimToEmpty(String str) {\r\nreturn str == null ? \"\" : str.trim();\r\n}<\/code><\/pre>\n\n\n\n\u6e90\u78bc\u89e3\u6790\uff1a\u5982\u679c\u8f38\u5165\u7684\u5b57\u7b26\u4e32\u70banull\uff0c\u5247\u8fd4\u56de\u7a7a\u4e32””\uff1b\u5426\u5247\u53bb\u9664\u6389\u5b57\u7b26\u4e32\u5169\u908a\u7684\u7a7a\u683c\u6216\u8005\u5236\u8868\u7b26\uff08tab\u9375\uff0c\u4e00\u500btab\u9375\u4ee3\u8868\u5169\u500b\u7a7a\u683c\uff09\u3002<\/p>\n\n\n\n
\n- trimToNull\u65b9\u6cd5\u6e90\u78bc\u8a73\u89e3\uff1a<\/li>\n<\/ul>\n\n\n\n
public static String trimToNull(String str) {\r\nString ts = trim(str);\r\nreturn isEmpty(ts) ? null : ts;\r\n}<\/code><\/pre>\n\n\n\n\u6e90\u78bc\u89e3\u6790\uff1a\u9996\u5148\u8abf\u7528trim()\u65b9\u6cd5\u8655\u7406\u8f38\u5165\u7684\u5b57\u7b26\u4e32\uff0c\u53bb\u9664\u5169\u908a\u7684\u7a7a\u683c\u6216\u5236\u8868\u7b26\uff08tab\u9375\uff0c\u4e00\u500btab\u9375\u4ee3\u8868\u5169\u500b\u7a7a\u683c\uff09\u3002<\/p>\n\n\n\n
\u5982\u679c\u8f38\u5165\u7684\u5b57\u7b26\u4e32\u70banull\uff0c\u5247\u8fd4\u56denull\uff1b\u63a5\u4e0b\u4f86\u5224\u65b7\u8655\u7406\u5f8c\u7684\u5b57\u7b26\u4e32\u662f\u5426\u70ba\u7a7a\uff0c\u5982\u679c\u70ba\u7a7a\u5247\u8fd4\u56denull\uff0c\u5426\u5247\u8fd4\u56dets\u3002<\/p>\n\n\n\n
\u7d9c\u4e0a\u6240\u8ff0\uff0ctrim\u65b9\u6cd5\u4e3b\u8981\u7528\u65bc\u53bb\u9664\u5b57\u7b26\u4e32\u5169\u908a\u7684\u7a7a\u683c\u6216\u5236\u8868\u7b26\uff0c\u800ctrimToEmpty\u548ctrimToNull\u5247\u6839\u64da\u4e0d\u540c\u7684\u60c5\u6cc1\u5206\u5225\u8fd4\u56de\u7a7a\u4e32\u6216null\u3002<\/p>\n\n\n\n
\u719f\u7df4\u638c\u63e1\u9019\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e6b\u52a9\u6211\u5011\u66f4\u9ad8\u6548\u5730\u9032\u884c\u5b57\u7b26\u4e32\u8655\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u672c\u6587\u5c07\u70ba\u60a8\u8a73\u89e3Java\u4e2d\u7684trim\u65b9\u6cd5\u53ca\u5176\u8b8a\u9ad4trimToEmpty\u548ctrimToNull\uff0c\u5e6b\u52a9\u60a8\u6df1\u5165\u7406\u89e3\u5b83\u5011\u5728\u5b57\u7b26\u4e32\u8655\u7406\u4e2d\u7684\u4f5c\u7528\u548c\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n","protected":false},"author":1,"featured_media":2749,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[145],"tags":[87,656,655,653,659,654,652],"aioseo_notices":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/hsin-life.com\/wp-content\/uploads\/2023\/04\/pexels-photo-546819-1.jpeg?fit=1880%2C1249&ssl=1","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/posts\/2748"}],"collection":[{"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/comments?post=2748"}],"version-history":[{"count":0,"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/posts\/2748\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/media\/2749"}],"wp:attachment":[{"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/media?parent=2748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/categories?post=2748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hsin-life.com\/wp-json\/wp\/v2\/tags?post=2748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}