c# - Adding a character from the end of a string
问题描述
I have a variety of strings in the following format:
WWSS1234519
S12319
etc.
All that I need to do is add a hyphen so that the 19 is separate. The above strings would become
This is C# in ASP.net, it's populating a gridview. Generic method with no insertions is:
<asp:Label ID="AccLabel" runat="server" Text='<%# Eval("Acc") %>' Width="96px"/>
WWSS12345-19
S123-19
etc.
What I tried was finding the indexof the string based on "19" but that will change come new years and I don't want to have to update the code every year to get the hyphen to appear.
I know there's a simple way to do this - Just not sure how.
Thank you.
解决方案
如果年份总是只是最后两个字符,只需插入:
var s = "WWSS1234519";
var formatted = s.Insert(s.Length - 2, "-");
推荐阅读
- r - R Parallel Package:clusterExport 到每个单独的核心,而不是一个大对象到所有核心
- python - 在 Pandas 中,我如何将选择日期列转换为行
- javascript - BPM 网格捕捉和绘制它的捕捉条
- mysql - Docker Compose:/mnt/sdb 总是满的
- reactjs - ReactJS 使用 SAML 与 Okta 身份提供程序集成
- rules - QGIS - 规则。使用查询查找穿越城市的道路
- windows - 无法通过 ssh 登录我没有密码的 Windows PC
- javascript - 是否可以检查事件的回调是否正在使用?
- mysql - 具有许多 IF 条件参数的 MySQL
- pthreads - pthread_t 声明需要是全局的吗?