A string constant had an improper %-sequence

You can insert characters into a string by entering a percent sign and then the ASCII hex value of the character. Percent-encoded literals are parsed to make sure they are of the form %hh, where h is a hexadecimal number. Improper codes (non-hex numbers) will trigger this error.

When you use a percent sign in a string, the relevance engine looks at the next two characters to see if they correspond to an ASCII hex value. For instance:

Q: "html uses %3Cangle brackets%3E"
A: html uses <angle brackets>
Q: "This is the %22truth%22" 
A: This is the "truth"

However, a string with a percent sign in it will return this error if either of the following conditions are true:

  • There are less than two characters in the string after the percent sign.
  • The two characters following the percent sign aren't valid hexadecimal characters (0-9, a-f, A-F).

You won’t get the error message if the percent sign is followed by letters or numbers, even if they don’t correspond to a valid ASCII value (00-7F). For instance:

Q: "html uses %3cangle brackets%9E"
A: html uses <angle brackets%9e

This may not give the desired result, because 9E is not a valid ASCII character, but it doesn't result in an error. However, this does:

Q: "html uses %3cangle brackets%9"
E: A string constant had an improper %-sequence.

This returns the error because the percent is followed by only one character.

Since the percent sign is an escape character, this means you can’t casually place it in a string literal. To get a percent sign into a string, use ‘%25’:

exists "c:\testfolder\percent%25.txt"

This expression returns true if you have a file named percent%.txt in the given folder. Note that this string will print out differently in the Fixlet debugger context:

q: "c:\testfolder\percent%25.txt"
A: c:\testfolder\percent%25.txt

This is because the value is re-inserted into the text until the final invocation, to ensure that a naked percent sign never gets exposed.