문자열 str;
str = str.substring (int beginindex);
str = str.substring (int beginindex, int endindex);
데모:
코드 사본은 다음과 같습니다.
수업 테스트
{
public static void main (String [] args)
{
문자열 S1 = "1234567890ABCDEFGH";
S1 = S1. 서브 스트링 (10);
System.out.println (S1);
}
}
실행 결과 : Abcdefgh
코드 사본은 다음과 같습니다.
수업 테스트
{
public static void main (String [] args)
{
문자열 S1 = "1234567890ABCDEFGH";
S1 = S1. 서브 스트링 (0,9);
System.out.println (S1);
}
}
실행 결과 : 123456789
다음은 일반적인 예입니다.
코드 사본은 다음과 같습니다.
공개 수업 stringdemo {
public static void main (String agrs []) {
String str = "이것은 내 원래 문자열입니다";
문자열 todelete = "Original";
if (str.startswith (Todelete))
str = str.substring (todelete.length ());
또 다른
if (str.endswith (Todelete))
str = str.substring (0, str.length ()-Todelete.length ());
또 다른
{
int index = str.indexof (Todelete);
if (index! = -1)
{
문자열 str1 = str.substring (0, index);
문자열 str2 = str.substring (index+todelete.length ());
str = str1+str2;
}
또 다른
System.out.println ( "String /" "+Todelete+" /"찾을 수 없음");
}
System.out.println (str);
}
}
실행 결과 :
이것은 내 끈입니다