I have a character vector in which each element is enclosed in brackets. I want to remove the brackets and just have the string.
So I tried:
n = c("[Dave]", "[Tony]", "[Sara]") paste("", n, "", sep="")
Unfortunately, this doesn't work for some reason.
I've performed the same task before using this same code, and am not sure why it's not working this time.
I want to go from '[Dave]'
to 'Dave'
.
What am I doing wrong?
Using strip() to Remove Brackets from the Beginning and End of Strings in Python. If your brackets are on the beginning and end of your string, you can also use the strip() function. The Python strip() function removes specified characters from the beginning and end of a string.
String test = "watching tv (at home)"; test = test. replaceAll("(",""); test = test. replaceAll(")","");
String s = "[abcdefg]"; s = s. replaceAll(regex, "");
String str = "Test Message (To Be removed)"; var test = str. replaceAll(RegExp('\\(. *? \\)'), ''); print(test);
You could gsub out the brackets like so:
n = c("[Dave]", "[Tony]", "[Sara]") gsub("\\[|\\]", "", n) [1] "Dave" "Tony" "Sara"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With