How To Delete String First / Last Character Using Java NetBeans
In this Java Tutorial we will see How To Delete The Char At The beginning Or The End Of A JTextFields Text ,On Jbutton Click Event The Program Will Remove Text Letter By Letter In Java NetBeans .
Project Source Code:
// remove first character
private void jButtonRFActionPerformed(java.awt.event.ActionEvent evt) {
if(jTextField1.getText().length() > 0)
{
String txtMinusFirstChar = jTextField1.getText().substring(1, jTextField1.getText().length());
jTextField1.setText(txtMinusFirstChar);
}
}
// remove last character
private void jButtonRLActionPerformed(java.awt.event.ActionEvent evt) {
if(jTextField1.getText().length() > 0)
{
String txtMinusLastChar = jTextField1.getText().substring(0, jTextField1.getText().length() - 1);
jTextField1.setText(txtMinusLastChar);
}
}
// remove first & last character
private void jButtonRFLActionPerformed(java.awt.event.ActionEvent evt) {
if(jTextField1.getText().length() > 1)
{
String txtMinusLFChar = jTextField1.getText().substring(1, jTextField1.getText().length() - 1);
jTextField1.setText(txtMinusLFChar);
}else{
jTextField1.setText("");
}
}
OutPut:
Download Projects Source Code