I want to delete all the full stops ( . ) in a string.
Therefore I tried: inpt = inpt.replaceAll(".", "");
,
but instead of deleting only the full stops, it deletes the entire content of the string.
Is it possible to delete only the full stops? Thank you for your answers!
The standard solution to remove punctuations from a String is using the replaceAll() method. It can remove each substring of the string that matches the given regular expression. You can use the POSIX character class \p{Punct} for creating a regular expression that finds punctuation characters.
Line Break: A line break (“\n”) is a single character that defines the line change. In order to replace all line breaks from strings replace() function can be used.
TrimEnd method removes characters from the end of a string, creating a new string object. An array of characters is passed to this method to specify the characters to be removed.
To replace the dots in a string, you need to escape the dot (.) and replace using the replace() method.
replaceAll
takes a regular expressions as an argument, and .
in a regex means "any character".
You can use replace
instead:
inpt = inpt.replace(".", "");
It will remove all occurences of .
.
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