How to insert spaces between the characters of a string

后端 未结 4 603
醉酒成梦
醉酒成梦 2021-01-14 08:01

Is there an easy method to insert spaces between the characters of a string? I\'m using the below code which takes a string (for example ( UI$.EmployeeHours * UI.DailySalar

4条回答
  •  無奈伤痛
    2021-01-14 08:38

    You can do that with regular expressions:

    using System.Text.RegularExpressions;
    class Program {
        static void Main() {
            string expression = "(UI$.SlNo-UI+UI$.Task)-(UI$.Responsible_Person*UI$.StartDate) ";
            string replaced = Regex.Replace(expression, @"([\w\$\.]+)", " [ $1 ] ");
        }
    }
    

    If you are not familiar with regular expressions this might look rather cryptic, but they are a powerful tool, and worth learning. In case, you may check how regular expressions work, and use a tool like Expresso to test your regular expressions.

    Hope this helps...

提交回复
热议问题