subString是String的一个方法,格式为:ide
public String substring(int beginIndex, int endIndex) spa
返回一个新字符串,它是此字符串的一个子字符串。索引
该子字符串从指定的 beginIndex 处开始,一直到索引 endIndex - 1 处的字符。所以,该子字符串的长度为 endIndex-beginIndex。 字符串
示例: get
截取str字符串的第2个和第三个。 string
String str = "123456789"; str =str.substring(1,3) it
结果:str="23" io
在Android应用中,删除按键的程序以下:List
button_15.setOnClickListener(new View.OnClickListener() { 程序
@Override
public void onClick(View v) {
editText=(EditText)findViewById(R.id.editText);
textContent=editText .getText().toString();
if(!"" .equals(textContent)){
//文本框中内容非空时执行删除操做
text=textContent .substring(0, textContent.length()-1);
editText.setText(text );
editText.setSelection(text .length());
}
}
});