在更改位置插入字符串

sil*_*ire 1 c# string token

我跌跌撞撞,我需要一些帮助.

我需要一种基于索引将子串插入更长字符串的方法.不幸的是,后续插入会使原始索引过时(因为字符串变得更长),我想知道是否有某种方法可以解决这个问题?

This is a hyperlink. And so is this.
          ^-------^            ^--^
         10      19           31  35
Run Code Online (Sandbox Code Playgroud)

首次插入后,第二个索引将更改:

This is a <a href="#">hyperlink. And so is this.
                                           ^--^
                              31          43  47
Run Code Online (Sandbox Code Playgroud)

有谁知道一个方法/库/算法来实现我想要的?

所以我神奇地可以插入,但仍然使用原始索引

Lua*_*aan 7

从最高指数替换为最低指数.只有你所替换之后的指数会发生变化,所以如果从最高点开始,你可以保持相同的指数,一切都会被正确替换,不需要调整.如果你只需要一次通过字符串,这是一个非常简单的解决方案:)

This is a hyperlink. And so is this.
          ^-------^            ^--^
         10      19           31  35

This is a hyperlink. And so is My new hyperlink this.
          ^-------^            ^-------------------^
         10      19           31

This is a another hyperlink. And so is My new hyperlink this.
          ^---------------^            ^-------------------^
         10
Run Code Online (Sandbox Code Playgroud)