Regular expression to truncate a String
Posted
by
user470184
on Stack Overflow
See other posts from Stack Overflow
or by user470184
Published on 2012-12-20T10:44:52Z
Indexed on
2012/12/20
11:03 UTC
Read the original article
Hit count: 167
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"
© Stack Overflow or respective owner