Regular expression to truncate a String
- by user470184
To truncate a String here is what I'm using :
String test1 = "this is test truncation 1.pdf";
String p1 = test1.substring(0, 10) + "...";
System.out.println(p1);
The output is 'this is te...'
How can I access the file name extension so that output becomes : 'this is te... pdf'
I could use substring method to access the last three characters but other file extensions could be 4 chars in length such as .aspx
Is there a regular expression I can use so that "this is test truncation 1.pdf" becomes "this is te... pdf"