OneBite.Dev - Coding blog in a bite size

cut a string in java

Code snippet on how to cut a string in java

  String str = "This is a sample string";
  String subString = str.substring(8,17); 

This code snippet takes a string, “This is a sample string” and cuts out a substring from it. The substring is taken from the 8th character up to, but not including, the 17th character. The first line declares a variable called str and sets it equal to the full string. The second line creates a new variable, subString, and sets it equal to the substring of str between the 8th character and the 17th character. The substring is then stored in the subString variable.

java