- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove newline, space and tab characters from a string in Java
To remove newline, space and tab characters from a string, replace them with empty as shown below.
replaceAll("[\
\t ]", "");
Above, the new line, tab, and space will get replaced with empty, since we have used replaceAll()
The following is the complete example.
Example
public class Demo { public static void main(String[] args) { String originalStr = "Demo
\tText"; System.out.println("Original String with tabs, spaces and newline:
"+originalStr); originalStr = originalStr.replaceAll("[\
\t ]", ""); System.out.println("
String after removing tabs, spaces and new line: "+originalStr); } }
Output
Original String with tabs, spaces and newline: Demo Text String after removing tabs, spaces and new line: DemoText
- Related Articles
- How to Remove Newline Characters from a text File?
- How to match tab and newline but not space using Python regular expression?
- How to Remove Characters from a String in Arduino?
- Remove characters from a string contained in another string with JavaScript?
- How can we eradicate leading and trailing space characters from a string in MySQL?
- How to remove certain characters from a string in C++?
- How to remove specific characters from a string in Python?
- JavaScript Remove non-duplicate characters from string
- JavaScript - Remove first n characters from string
- Remove all non-alphabetical characters of a String in Java?
- Remove new lines from a string and replace with one empty space PHP?
- Remove characters in a range from a Java StringBuffer Object
- Program to remove duplicate characters from a given string in Python
- C# Program to remove duplicate characters from String
- How to remove all special characters, punctuation and spaces from a string in Python?

Advertisements