Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Remove full stop in string

Tags:

java

replace

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!

like image 293
IndexOutOfBoundsException Avatar asked Feb 16 '13 10:02

IndexOutOfBoundsException


People also ask

How do you remove the dots from a string in Java?

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.

How do you remove a line break in Java?

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.

How do I remove a character from the end of a string?

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.

How do you replace a dot in a string?

To replace the dots in a string, you need to escape the dot (.) and replace using the replace() method.


1 Answers

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 ..

like image 181
assylias Avatar answered Oct 13 '22 01:10

assylias