Advertisement
ivandrofly

Remove inner wrapped tag

Apr 6th, 2024
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1.             string RemoveWrapped(string inp)
  2.             {
  3.                 var lastIndex = inp.IndexOf("</i>", StringComparison.Ordinal);
  4.                 if (lastIndex < 0) return inp;
  5.                 var index = inp.IndexOf("<i>", 0, lastIndex, StringComparison.Ordinal);
  6.                 if (index < 0) return inp;
  7.                 var nearestClosingIndex = inp.IndexOf("</i>", index + 4, lastIndex - index, StringComparison.Ordinal);
  8.                 if (nearestClosingIndex != lastIndex) return inp;
  9.                 inp = inp.Remove(nearestClosingIndex, 4);
  10.                 var nearestIndexFromRemoved = text.LastIndexOf("<i>", nearestClosingIndex, StringComparison.Ordinal);
  11.                 if (nearestIndexFromRemoved == index) return inp;
  12.                 return inp.Remove(nearestIndexFromRemoved, 3);
  13.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement