Visual Studio 2005: \a escape sequence appears in string but can't remove
-
13-06-2021 - |
Pregunta
I'm working in J# with text extracted from MS Word using Excel interop. Right now I'm having a problem with text extracted from a cell. The cell is a row header, the visible text is "Total", but the extracted string is "Total\r\a". I want to remove the escape sequence, but VS won't detect or remove \a.
cellText = cellText.Replace("\r", ""); //works
cellText = cellText.Replace("\a", ""); //error: unrecognized escape sequence
cellText = cellText.Replace("\\a", ""); //doesn't remove the sequence
cellText.Contains("\\a") returns false.
Any ideas?
No hay solución correcta
Otros consejos
cellText = cellText.Replace("\a", ""); //error: unrecognized escape sequence
Well, \a
is the standard escape sequence for C-like languages for the alert (bell) character, which usually makes a sound if sent to the console. But Java doesn't support it (although most of the others are ok). However, you can use a hex escape:
cellText = cellText.Replace("\u0007", "");
or an octal escape:
cellText = cellText.Replace("\007", "");
or if you're desperate to avoid the evil escape sequences:
char bell = 7;
cellText = cellText.Replace(bell.toString(), "");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow