-1

Possible Duplicate:
up to first N characters
I need to “trim” my variable called: “TITLE” to only 40 characters

Java: Limiting/Trim/ Removing extra characters from string. I want to remove any extra characters after 40 characters of a string variable.

Community
  • 1
  • 1

1 Answers1

2
String shortString = longString.substring(0, Math.min(longString.length(), 40));

You might like to take a closer look at the String class

snibbets
  • 1,095
  • 10
  • 11
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366