Thursday, 19 December 2013

Remove non Ascii characters from strings

public class Sample {
    public static void main(String a[]){
        String str = "GHj��PL����AM�";
        System.out.println(str);
        str = str.replaceAll("[^\\p{ASCII}]", "");
        System.out.println("After removing non ASCII chars:");
        System.out.println(str);
    }
}
 System.out.println("here dec after con is "+decryptedContent.replaceAll("[^\\p{ASCII}]", "").trim());
OUTPUT
After removing non ASCII chars:
GHjPLAM 



Remove HTML Tags

public class HtmlTagRemover {
    public static void main(String a[]){
        String text = "<B>Remove tags<\\B>";
        System.out.println(text);
        text = text.replaceAll("\\<.*?\\>", "");
        System.out.println(text);
    }
}


OUTPUT
 "<B>Remove tags<\B>
Remove tags
 

  public class multipleSpaces {
    public static void main(String[] args) {
      
                String str = "String    With Multiple      Spaces";
                StringTokenizer st = new StringTokenizer(str, " ");
                StringBuffer sb = new StringBuffer();
                while(st.hasMoreElements()){
                    sb.append(st.nextElement()).append(" ");
                }
                System.out.println(sb.toString().trim());
            }
        }

 

 

 

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...