我的 strings.xml 文件保存了一个 SQL 查询,我想在代码中用 String.Format 构造最终字符串。SELECT 查询中有一个类似下面这样的 like 子句。
SELECT ColumnA, ColumnB FROM records WHERE ColumnA LIKE '%pattern%'
为了格式化,我用 %1$s 替换 'pattern',得到下面这样。
SELECT ColumnA, ColumnB FROM records WHERE ColumnA LIKE \'%%1$s%\'
反斜杠可以转义单引号。但是 % 字符我还没能成功转义。
怎样把 like 子句放进 strings.xml 文件?
从英语翻译·查看原文My strings.xml file holds a SQL query, and I'm trying to construct the finished string in code with String.Format. The SELECT query contains a like clause along these lines:
SELECT ColumnA, ColumnB FROM records WHERE ColumnA LIKE '%pattern%'
For formatting, I substitute %1$s for 'pattern', giving me:
SELECT ColumnA, ColumnB FROM records WHERE ColumnA LIKE \'%%1$s%\'
Backslashes let me escape the single quotes. The % character, however, is something I haven't managed to escape.
What is the way to put a like clause into strings.xml?