Question Detail

How to use Substring in java ?

1 years ago Views 215 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

- 1 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

- 1 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  

 }  

}