- package com.instanceofjava;
- class RemoveNonASCIIString{
- public static void main(String [] args){
- String str = "Instance��of��java";
- System.out.println(str);
- str = str.replaceAll("[^\\p{ASCII}]", "");
- System.out.println("After removing non ASCII chars:");
- System.out.println(str);
- }
- }
- Instance��of��java
- After removing non ASCII chars:
- Instanceofjava
#2: Java Program to Remove multiple spaces in a string
- package com.instanceofjava;
- class RemoveNonASCIIString{
- public static void main(String [] args){
- String str = "Instance of java";
- StringTokenizer st = new StringTokenizer(str, " ");
- StringBuffer sb = new StringBuffer();
- while(st.hasMoreElements()){
- sb.append(st.nextElement()).append(" ");
- }
- System.out.println(sb.toString().trim());
- }
- }
- }
Output:
- Instance of java
No comments