TextWithMnemonic (String textWithMnemonic) { if (textWithMnemonic == null) { throw new IllegalArgumentException("textWithMnemonic cannot be null"); } // Parsing is copied from Presentation.setText(String, boolean) int index = -1; final StringBuilder plainText = new StringBuilder(); for (int i = 0; i < textWithMnemonic.length(); i++) { char ch = textWithMnemonic.charAt(i); if (ch == '&') { i++; if (i >= textWithMnemonic.length()) { break; } ch = textWithMnemonic.charAt(i); if (ch != '&') { index = plainText.length(); } } plainText.append(ch); } return new TextWithMnemonic(plainText.toString(), index); }