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 - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -