String str;
str=str.substring (int beginindex); intercepts the string of STR from the first letter length to Beginindex, assigning the remaining string to STR;
str=str.substring (int beginindex,int endindex); intercepts the string from the beginning of the beginindex to the end of the Endindex in STR and assigns it to STR;
Demo
Copy Code code as follows:
Class Test
{
public static void Main (string[] args)
{
String S1 = "1234567890ABCDEFGH";
S1 = s1.substring (10);
System.out.println (S1);
}
}
Run Result: abcdefgh
Copy Code code as follows:
Class Test
{
public static void Main (string[] args)
{
String S1 = "1234567890ABCDEFGH";
S1 = s1.substring (0,9);
System.out.println (S1);
}
}
Run Result: 123456789
Here is a typical example:
Copy Code code as follows:
public class stringdemo{
public static void Main (String agrs[]) {
String Str= "This are my original string";
String todelete= "original";
if (Str.startswith (Todelete))
Str=str.substring (Todelete.length ());
Else
if (Str.endswith (Todelete))
Str=str.substring (0, Str.length ()-todelete.length ());
Else
{
int Index=str.indexof (todelete);
if (index!=-1)
{
String str1=str.substring (0, index);
String str2=str.substring (Index+todelete.length ());
STR=STR1+STR2;
}
Else
System.out.println ("string/" "+todelete+"/"Not Found");
}
System.out.println (str);
}
}
Run Result:
This are my string