如何逃脱的String.Format%? [英] How to escape % in String.Format?

查看:139
本文介绍了如何逃脱的String.Format%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保存在我的strings.xml文件中的SQL查询,我想用的String.Format 打造code中的最后一个字符串。该 SELECT 语句使用一个像,像这样:

I am storing a SQL query in my strings.xml file and I want to use String.Format to build the final string in code. The SELECT statement uses a like, something like this:

SELECT Field1, Field2 FROM mytable WHERE Field1 LIKE '%something%'

为了格式化,我代替'东西'%1 $ s的所以它变成了:

In order to format that I replace 'something' with %1$s so it becomes:

SELECT Field1, Field2 FROM mytable WHERE Field1 LIKE \'%%1$s%\'

我逃避单引号与反斜杠。但是我不能够逃脱%标志。

I escape the single quotes with the backslash. However I am not able to escape the % sign.

我怎么能包括在我的strings.xml文件中的声明一样?

How can I include a like statement in my strings.xml file?

推荐答案

要逃避,你需要加倍起来: %%

To escape %, you will need to double it up: %%.

这篇关于如何逃脱的String.Format%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆