Oren Jus
Oren Jus

Reputation: 11

How to delete one character before and after character #?

How to delete 1 string before and after character #

For Example: I have string: ABC#DEF and I want to result: ABEF

Upvotes: 0

Views: 153

Answers (2)

Akash Shrivastava
Akash Shrivastava

Reputation: 1365

You can use regular expression to split by one char before and after #.

String.Join("", System.Text.RegularExpressions.Regex.Split("ABC#DEF", @".#."))

Upvotes: 3

The simple way, you can do:

  1. pos = <yourStringVariable>.IndexOf('#') -> find '#' position
  2. target = yourStringVariable.Substring(pos - 1, 3) -> get '#' and the next and previous one
  3. yourStringVariable.Replace(target, "") -> clear them in string.

Upvotes: 1

Related Questions