Domanda

I have a string like the following.

ABC {A WELL-KNOWN MAGICIAN} WILL PERFORM AT {0} FOR {1} HOURS.

There is no placeholder for the first pair of curly braces. When I pass this string to MessageFormat.format(String, Object[]) method with an object array containing two strings to replace the placeholders {0} and {1}, I get the following error.

java.lang.IllegalArgumentException: All argument identifiers have to be either non-negative numbers or strings following the pattern ([:ID_Start:] [:ID_Continue:]*).

It appears that the first pair of brace is being parsed for the first placeholder and since it is not a valid placeholder, the error occurs.

How can I tell MessageFormat.format to ignore the first pair of curly braces and work with the other two?

È stato utile?

Soluzione

Put a pair of single quotes around the part you don't want to be treated as parameter placeholders. i.e.

ABC '{A WELL-KNOWN MAGICIAN}' WILL PERFORM AT {0} FOR {1} HOURS.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top