Eliminate invisible new line or blank charecters in a string using java

Some times when we process string output from different other sources we will end up having invisible blank or new line or some tabbed characters which will annoy us from parsing that string for a particular thing. In that case while using Java we can use Trim method which helps a lot on this situation.

Another great quality of this trim method is , it can remove blank like characters from both sides of strings .
This method removes the blank spaces from both ends of the given string (Front and End).

A Simple example below might be helpful to use this

public class StringTrim{
  public static void main(String[] args) {
  System.out.println("String trim example!");
  String str = " [RoseIndia, hi, hello]   ";
  System.out.println("Given String :" + str);
  System.out.println("After trim :" +str.trim());

OutPut :
Given String : [RoseIndia, hi, hello]   
After trim :[RoseIndia, hi, hello]

0 comments to "Eliminate invisible new line or blank charecters in a string using java"

Post a Comment

Who ever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs u can at least use Name/URL option which don’t even require any sign-in, good thing is that it can accept your lovely nick name also and URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")
వీలయితే నాల్గు పోస్టులు ...కుదురితే ఒక కామెంటూ ...


Enter your email address:

Buffs ...


hits counter
View My StatsCheck Google Page Rank

Add to Google Reader or Homepage

Bookmark and Share


Powered by WidgetsForFree