How to replace part of string by position?

后端 未结 18 879
逝去的感伤
逝去的感伤 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:26

    Use String.Substring() (details here) to cut left part, then your replacement, then right part. Play with indexes until you get it right :)

    Something like:

    string replacement=original.Substring(0,start)+
        rep+original.Substring(start+rep.Length);
    

提交回复
热议问题