Question Detail

How to use Substring in java ?

6 years ago Views 1572 Visit Post Reply

I have a String "This is my String Cut it."
i want to cut this String and show only "This is my String"
how can I do it in java or android?


Thread Reply

Bili Greed

- 6 years ago

In java substring is a function which will cut given String as you want just enter your requirement.

Try below syntax : 

String str= "Here Your String";

System.out.println(str.substring(5,16));

Kanhaiya

- 6 years ago

public class TestSubstring{  

 public static void main(String args[]){  

   String s="SachinTendulkar";  

   System.out.println(s.substring(6));//Tendulkar  

   System.out.println(s.substring(0,6));//Sachin  

 }  

}