Question

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 correct solution

OTHER TIPS

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(), "");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top