The Artima Developer Community
Sponsored Link

Java Buzz Forum
Remove non ascii character from string

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Remove non ascii character from string Posted: Sep 18, 2015 10:30 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Remove non ascii character from string
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
#1: Java Program to Remove non ASCII chars from String

  1. package com.instanceofjava;
  2.  
  3. class RemoveNonASCIIString{
  4.  
  5. public static void main(String [] args){ 

  6.   String str = "Instance��of��java";
  7.   System.out.println(str);
  8.  
  9.   str = str.replaceAll("[^\\p{ASCII}]", "");
  10.  
  11.   System.out.println("After removing non ASCII chars:");
  12.  
  13.   System.out.println(str);
  14. }
  15. }
Output:
  1. Instance��of��java
  2. After removing non ASCII chars:
  3. Instanceofjava


#2: Java Program to Remove multiple spaces in a string

  1. package com.instanceofjava;
  2.  
  3. class RemoveNonASCIIString{
  4.  
  5. public static void main(String [] args){ 

  6.   String str = "Instance  of    java";
  7.   StringTokenizer st = new StringTokenizer(str, " ");
  8.  
  9.   StringBuffer sb = new StringBuffer();
  10.  
  11.   while(st.hasMoreElements()){
  12.          sb.append(st.nextElement()).append(" ");
  13.   }
  14.  
  15.      System.out.println(sb.toString().trim());
  16.     
  17.     }
  18. }
  19. }
Output:
  1. Instance of java

Read: Remove non ascii character from string

Topic: Test Double Patterns Previous Topic   Next Topic Topic: Low Latency in Java 8

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use