Home Java Beginners Taking Substring



Taking Substring
Posted on: June 29, 2007 at 12:00 AM
In this example we are taking a sub string from a given string.

Taking  Substring

     

In this example we are taking a sub string from a given string.

In this example we are creating an string object .We initialize this string object as "Rajesh Kumar". We are taking sub string by use of substring()  method.

The methods used:
substring(int i):
This method is used to find all sub string after index i.

substring(int start,int end):
This is used to find the substring between start and end point.

The code of the program is given below:

public class SubstringExample1{
  public static void main(String[] args){
  String string = "Rajesh kumar"
  System.out.println("String : " + string);
  String substring = string.substring(3);
  System.out.println("String after 3rd index:
 " 
+ substring)
  substring = string.substring(12);
  System.out.println("Substring (1,2): " 
substring
);
  }
}

The output of the program is given below:

C:\convert\rajesh\completed>javac SubstringExample1.java
C:\convert\rajesh\completed>java SubstringExample1
String : Rajesh kumar
String after 3rd index: esh kumar
Substring (1,2): a

Download this example.

Related Tags for Taking Substring:
cstringobjectmethodthissubstringexampleiniexamsheitbstrliinitusesubstrinitializeinsubasmtrjesmeobjcreatingxaxampssubstatkismpleaarstrsubstzssriringthsubsstatiinitialjepleplo


More Tutorials from this section

Ask Questions?    Discuss: Taking Substring   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.