Is there an easy way to remove the first 2 and last 2 chars in a string?
I have this string:
\nTESTSTRING\n
How could I easily delete them?
Is there an easy way to remove the first 2 and last 2 chars in a string?
I have this string:
\nTESTSTRING\n
How could I easily delete them?
Papuccino1,
If you create an extension method like this:
your code will be simplified and will be safer (not depending on dangerous index):
I hope this helps,
Ricardo Lacerda Castelo Branco
Did you try:
Of course you must test that the string contains more than 4 chars before doing this. Also in your case it seems that \n is a single newline character. If all you want to do is remove leading and trailing whitespaces, you should use
as suggested by Charles
Its Simple with
Substring
andRemove
methods, as detailed in this link: