码迷,mamicode.com
首页 > 编程语言 > 详细

java trim start end space

时间:2018-04-25 20:12:58      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:start   lin   ring   print   hat   main   sys   line   pre   

Java program that trims starts and ends

public class Program {

    public static String trimEnd(String value) {
        // Use replaceFirst to remove trailing spaces.
        return value.replaceFirst("\\s+$", "");
    }

    public static String trimStart(String value) {
        // Remove leading spaces.
        return value.replaceFirst("^\\s+", "");
    }

    public static void main(String[] args) {

        String value = "  /Test?  ";
        // Use custom trimEnd and trimStart methods.
        System.out.println("[" + trimEnd(value) + "]");
        System.out.println("[" + trimStart(value) + "]");
    }
}

java trim start end space

标签:start   lin   ring   print   hat   main   sys   line   pre   

原文地址:https://www.cnblogs.com/kakaisgood/p/8946597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!