How to replace part of string by position?

后端 未结 18 888
逝去的感伤
逝去的感伤 2020-11-28 04:37

I have this string: ABCDEFGHIJ

I need to replace from position 4 to position 5 with the string ZX

It will look like this: ABC

18条回答
  •  难免孤独
    2020-11-28 05:36

    Yet another

        public static string ReplaceAtPosition(this string self, int position, string newValue)        
        {
            return self.Remove(position, newValue.Length).Insert(position, newValue); 
        }
    

提交回复
热议问题