Reputation: 11
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
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
Reputation: 107
The simple way, you can do:
pos = <yourStringVariable>.IndexOf('#')
-> find '#' positiontarget = yourStringVariable.Substring(pos - 1, 3)
-> get '#' and the next and previous oneyourStringVariable.Replace(target, "")
-> clear them in string.Upvotes: 1