在字符串之间添加空格 [英] Adding spaces between the string
本文介绍了在字符串之间添加空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个字符串,我从数据库中检索,显示为
ex-2012-04- 02T12:04:47.9010868 + 10:00
现在,我希望显示它像2012-04-02 T 12:04:47.9010868 + 10:00
非常紧急请提出一些解决方案。
问候
Hi All,
I have one string which i am retrieving from database which is displaying like
ex-2012-04-02T12:04:47.9010868+10:00
Now ,I want to display it like 2012-04-02 T 12:04:47.9010868 + 10:00
Its very urgent pls suggest some solutions.
Regards
推荐答案
如果你从数据库中检索它作为一个字符串(即它存储为一个字符串而不是一个DateTime字段),你别无选择,只能把它分解成它的组成部分sith Substring and用你想要的空间重新组装它。但是将它存储在DateTime字段中要好得多,因为它们更灵活。
如果你将它存储为DateTime,那么你们所有人需要做的是在将其转换为字符串进行显示时指定所需的确切格式:格式化日期时间以显示 - 格式字符串描述 [ ^ ]会有所帮助。
If you are retrieving it from the database as a string (i.e. it is stored as a string rather than a DateTime field) then you have no choice but to break it into it''s constituent parts sith Substring and reassemble it with the spaces where you want. But it would be a lot better to store it in a DateTime field instead as these are a lot more flexible.
If you store it as a DateTime, then all you need to do is specify the exact format you want when you convert it to a string for display: Formatting a DateTime for display - format string description[^] will help.
试试这个
Try this
"2012-04-02T12:04:47.9010868+10:00".Tostring().Replace("T"," T ").Replace("+"," + ")
快乐的编码!
:)
Happy Coding!
:)
这篇关于在字符串之间添加空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文