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
import 
java.lang.*;

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

Whoever 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 doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")

Popular Posts

Enter your email address:

Buffs ...

Tags


Powered by WidgetsForFree