Home Java: removing multiple occurrences of unprintable characters from group
Reply: 0

Java: removing multiple occurrences of unprintable characters from group

user2079
1#
user2079 Published in April 23, 2018, 9:21 am

In out application we need to compare and manipulate functions code like the following:

function void disableTestOnDevice(SampleBuilder sample,String devices,String[] devTestCode) {\r\n\t\t   if(devices == null)\r\n\t\t\t   return;\r\n\t       if(sample.getListTransc() != null && sample.getListTransc().size() > 0){\t\r\n\t\t\t\tfor(int i = sample.getListTransc().size()-1; i >= 0; i--){\r\n\t\t\t\t\tViewWorklistBuilder j = (ViewWorklistBuilder)sample.getListTransc().get(i);\r\n\t\t\t\t\tif(j.getDeviceId() == null || j.getDeviceTestCode() == null || j.getDeviceSpecimenCode() == null){\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(j.getDeviceId().equals(devices)){\r\n\t\t\t\t\t\tif(devTestCode != null){\r\n\t\t\t\t\t\t\tfor(int k = 0;  k < devTestCode.length; k++){\r\n\t\t\t\t\t\t\t\tif(j.getDeviceTestCode().equals(devTestCode[k])){\r\n\t\t\t\t\t\t\t\t\tj.setEnabled(0);\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\t\r\n\t\t\t\t}\r\n\t       }\r\n\t\r\n

Sometimes it happens that some extra \t, \r or \n is added, I don't know why. So, before comparing two functions (two String objects) I would like to remove multiple occurrences of unprintable characters from each group. For example, a group like \r\n\t\r\n should become \t\r\n

Or maybe, something like

if(devices == null)\r\n\t\t\t   return;\r\n\t\t
for(int i = sample.getListTransc().size()-1; i >= 0; i--){\t\r\n\t\t\t\tSystem.out.println(i);\t\r\n\t\t\t\}

should become

if(devices == null)\r\n\t   return;\r\n\t
for(int i = sample.getListTransc().size()-1; i >= 0; i--){\t\r\nSystem.out.println(i);\t\r\n}

Or maybe, my problem could be a little more insidious. I mean that it may be necessary that any group of unprintable characters matching \r\n\t should become \n\t

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.419132 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO