Posted By:
rajjan_js
Posted On:
Wednesday, March 28, 2001 10:13 PM
Hi i wrote one own class and a mehtod for your problem . Take it use the method in awt program.
/********class :splitString***********/
/********Author:Rajjan.j.s************/
/********Date :29-03-2001************/
class splitString{
public static void main(String []a)
{
String ar="hi i am a user";
System.out.println(" "+ar);
System.out.println(" "+methodSplitString(ar,3,5)); // call the method here
}
/******** this is the method which will return the string from the given starting index
and the total number of characters **********************/
public static String methodSplitString(String iniString,int startIndex , int totalChar)
{
//int len=iniString.length;
String finalString="";
iniString=iniString+1; // make the first char at '1' because String index start from zero
/* trims the blank spaces before the starting index position */
while( iniString.charAt(startIndex) != ' ')
{
startIndex++;
}
int i=startIndex;
int j=0;
/* extraction will be done here */
while(j!=totalChar)
{
if(iniString.charAt(i) == ' ')
{
// nothing // totalChar++;
}
else{
finalString+=""+iniString.charAt(i);
j++;
}
i++;
}
return finalString;
}
}