逃逸单引号中的String.Format() [英] Escaping single quote in String.Format()

查看:1293
本文介绍了逃逸单引号中的String.Format()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直都在管​​,我不明白这一个。可能是简单的。

I have been all over the 'tubes and I can't figure this one out. Might be simple.

下面的的String.Format 电话:

return dt.ToString("MMM d yy 'at' H:mmm");

正确地返回这样的:

Correctly returns this:

08年9月23日,在12时五十七

Sep 23 08 at 12:57

现在,让我们说,我想添加一个单引号的前一年,回到这一点:

Now let's say I want to add a single quote before the year, to return this:

09月23日08时12:57

Sep 23 '08 at 12:57

由于单引号是保留转义字符,我怎么逃单引号才能正常显示?

Since the single quote is a reserved escape character, how do I escape the single quote to get it to display?

我已经试过双人间,三人间和四单引号,没有运气。

I have tried double, triple, and quad single quotes, with no luck.

推荐答案

您可以使用反斜杠,你将不得不逃逃吧。无论是

You can escape it using a backslash which you will have to escape. Either

return dt.ToString(@"MMM d \'yy 'at' H:mmm");

return dt.ToString("MMM d \\'yy 'at' H:mmm");

这篇关于逃逸单引号中的String.Format()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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