I have a byte array which is filled by a serial port event and code is shown below:
private InputStream input = null;
......
......
public void SerialEvent(SerialEvent se){
if(se.getEventType == SerialPortEvent.DATA_AVAILABLE){
int length = input.available();
if(length > 0){
byte[] array = new byte[length];
int numBytes = input.read(array);
String text = new String(array);
}
}
}
The variable text
contains the below characters,
"33[K", "33[m", "33[H2J", "33[6;1H" ,"33[?12l", "33[?25h", "33[5i", "33[4i", "33i" and similar types..
As of now, I use String.replace
to remove all these characters from the string.
I have tried new String(array , 'CharSet'); //Tried with all CharSet options
but I couldn't able to remove those.
Is there any way where I can remove those characters without using replace method?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…