简体   繁体   English

Java 业务规则应用于设置器以限制字符串长度并在超出限制时插入空间

[英]Java Business Rule to apply to setter to limit String length and insert space if limit exceeded

I have this setter method:我有这个设置方法:

        public void setCgp_name(String cgp_name) {
        this.cgp_name = cgp_name;
    }

Basically when the user inserts a long string such as ARG,AUS,BEL,BRA,DNK,FRA,ITA,GBR,USA without any spaces between the commas this info is placed into a table and it will break the boundaries of the table.基本上,当用户插入一个长字符串(例如 ARG、AUS、BEL、BRA、DNK、FRA、ITA、GBR、USA)时,逗号之间没有任何空格,此信息将被放入一个表中,它将打破表的边界。 I am trying to apply a business rule to this setter so that if the user enters something like this: ARG,AUS,BEL,BRA,DNK,FRA,ITA,GBR,USA a space will be added in somewhere to prevent the formatting issue in the table.我正在尝试将业务规则应用于此设置器,以便如果用户输入如下内容:ARG,AUS,BEL,BRA,DNK,FRA,ITA,GBR,USA 将在某处添加空格以防止格式问题在表中。 The word wrapping works when spaces are present but not with long strings.当存在空格但不包含长字符串时,自动换行有效。

    public void setCgp_name(String cgp_name) {

        cgp_name = cgp_name.replaceAll(",[ ]*", ", ");

        this.cgp_name = cgp_name;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM