文字列str;
str = str.substring(int beginindex);
str = str.substring(int beginindex、int endindex);
デモ:
コードコピーは次のとおりです。
クラステスト
{
public static void main(string [] args)
{
文字列S1 = "1234567890ABCDEFGH";
S1 = S1.Substring(10);
System.out.println(s1);
}
}
ランニング結果:ABCDEFGH
コードコピーは次のとおりです。
クラステスト
{
public static void main(string [] args)
{
文字列S1 = "1234567890ABCDEFGH";
S1 = S1.Substring(0,9);
System.out.println(s1);
}
}
ランニング結果:123456789
典型的な例は次のとおりです。
コードコピーは次のとおりです。
パブリッククラスのstringdemo {
public static void main(string agrs []){
文字列str = "これは私の元の文字列です";
string 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)
{
string str1 = str.substring(0、index);
string str2 = str.substring(index+todelete.length());
str = str1+str2;
}
それ以外
system.out.println( "string /" "+todelete+" /"not not ing");
}
System.out.println(str);
}
}
実行結果:
これは私の文字列です