c# - Regex Ignore first and last terminator -


i have string in text have uses | delimiter.

example:

|2p|1|u|f8| 

i want result 2p|1|u|f8. how can that?

the regex easy, why not use trim():

var str = "|2p|1|u|f8|"; str = str.trim(new[] {'|'}); 

or without new[] {...}:

str = str.trim('|'); 

output:

enter image description here

in case there leading/trailing whitespaces, can use chained trims:

var str = "\r\n |2p|1|u|f8|   \r\n"; str = str.trim().trim('|'); 

output same.


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -