How to add characters to a string in C#

前端 未结 4 786
时光说笑
时光说笑 2021-01-21 03:13

Problem: I would like add characters to a phone.

So instead of displaying ###-###-####, I would like to display (###) ###-####.

I tried the foll

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 03:37

    To insert string in particular position you can use Insert function.

    Here is an example:

    string phone = "111-222-8765";
    phone = phone.Insert(0, "("); // (111-222-8765
    phone = phone.Insert(3, ")"); // (111)-222-8765
    

提交回复
热议问题