c# - How can I format a variable and make it into a string with a message and zeros in front of it?
问题描述
My code has this for PhraseNum:
public string PhraseNum { get => _phraseNum; set => SetProperty(ref _phraseNum, value); }
What I would like is for instead of just displaying the number, that it displays something like this:
Id: 00044
So with the characters "Id:" in front, then a space and then padded to five digits.
解决方案
最简单的方法是ToString
使用以下格式调用 int 对象上的方法:
using System.Globalization;
int _phraseNum = 123;
_phraseNum.ToString("Id: 00000", CultureInfo.InvariantCulture); //outputs "Id: 00123"
推荐阅读
- azure - 从 Docker 容器将数据记录到 Azure Application Insights
- java - 确定数组中某个值的邻居加起来是否达到设定值?
- rxjs - 所有冷的 observables 都是单播的,所有的 hot observables 都是多播的吗?
- git - Composer no-dev 仍在安装 git 存储库
- java - @RequestParam 任何值
- c# - NLog VS Windows.Identity.Impersonate()
- dialogflow-es - 谷歌行动 | 代理上下文在 agent.context.get() 中给出“-”
- google-apps-script - MailApp.sendEmail 向非收件人的用户发送电子邮件
- azure-devops - 为测试自动化框架设置 Azure Pipeline
- linker - dyld:未加载库:但库似乎完全不相关