如何在字符串连接中使用三元运算符来检查字符串的长度
How to use ternary operator in String concatenation, to check length of String
代码:
"No. Siri Pendaftaran : " + ($F{ref_no}.length() > 10) ? $F{ref_no} : $F{ref_no}.substring(0,20)+ "..."
错误:
Type mismatch: cannot convert from String to boolean
Errors were encountered when compiling report expressions class file:
在字符串连接中使用三元运算符时,您需要在表达式周围包含 ()
以便正确计算它
这会起作用
"No. Siri Pendaftaran : " + (($F{ref_no}.length() > 10) ? $F{ref_no} : $F{ref_no}.substring(0,20))+ "..."
这么说我觉得你在找这个表情
"No. Siri Pendaftaran : " + (($F{ref_no}.length() <= 10) ? $F{ref_no} : ($F{ref_no}.substring(0,10)+ "..."))
代码:
"No. Siri Pendaftaran : " + ($F{ref_no}.length() > 10) ? $F{ref_no} : $F{ref_no}.substring(0,20)+ "..."
错误:
Type mismatch: cannot convert from String to boolean
Errors were encountered when compiling report expressions class file:
在字符串连接中使用三元运算符时,您需要在表达式周围包含 ()
以便正确计算它
这会起作用
"No. Siri Pendaftaran : " + (($F{ref_no}.length() > 10) ? $F{ref_no} : $F{ref_no}.substring(0,20))+ "..."
这么说我觉得你在找这个表情
"No. Siri Pendaftaran : " + (($F{ref_no}.length() <= 10) ? $F{ref_no} : ($F{ref_no}.substring(0,10)+ "..."))