.Net Core Replace First 方法

	/// <summary>
        /// 替换第一个匹配的字符
        /// </summary>
        /// <param name="text"></param>
        /// <param name="search"></param>
        /// <param name="replace"></param>
        /// <returns></returns>
        public static string ReplaceFirst(string text, string search, string replace)
        {
            int pos = text.IndexOf(search);
            if (pos < 0)
            {
                return text;
            }
            return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
        }		

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×