C#替换指定位置字符串-将指定位置数字替换成本身2倍


            string text = "12,110,30,30,30,30,30,30";
            int index = 1;
            string[] txts = text.Split(',');
            if (txts.Length >= index)
            {
                MatchCollection matches = Regex.Matches(text, ",");
                int startIdx = 0;
                if (index != 1)
                    startIdx = matches[index - 2].Index + 1;
                int endIdx = text.Length;
                if (index != txts.Length)
                    endIdx = matches[index - 1].Index;
                string value1 = text.Substring(startIdx, endIdx - startIdx);
                int value = Convert.ToInt32(value1);
                text = text.Remove(startIdx, endIdx - startIdx).Insert(startIdx, Convert.ToString(value * 2));
            }

猜你喜欢

转载自blog.csdn.net/weixin_38660590/article/details/80934637