Mis3
4 years agoFrequent Contributor
Please help me to improve my awkward code
Below is my code to validate an input string. It is working but it is awkward. Any suggestions to improve the code?
1. First I check if the input string. If it does not start with 431, 1431, 204 or 1204, exit the loop.
2. Then I check if the input string starts with "1". If not, add "1" to the string.
Thanks.
rowdata = rowsData[i]
String[] data = rowdata.split(",")
if ( !rowdata.startsWith('431') && !rowdata.startsWith('1431') && !rowdata.startsWith('204') && !rowdata.startsWith('1204') )
{
log.info " Seq="+i+ " Invalid line " + " ["+ data[0] + "]"
report << '\n'+sdf.format(log_date)+" Seq="+i+ " Invalid line " + "[" + data[0] + "]"
continue
}
if ( rowdata.startsWith('1') )
{ msisdn_1 = data[0] }
else
{ msisdn_1 = "1" + data[0] }