• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

replacing characters

 
Ranch Hand
Posts: 111
Eclipse IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am trying to replace a strange character from an string.


replaceAll does not work with � , it returns the same string "asdf�"

I notice that � this character does not exits in the ascii code, � � exits in the extended ascci code but not � alone.

I have looked into the character api but I dont found anything usefull.

Any idea to replace the � from an string?
Is there any method that returns the ascii code from a character?

Thanks.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class TestString{
public static void replaceStr(){
String trial1="";
String trial2="arun'";
trial1=trial2.replaceAll("\'","");
System.out.println(trial2);
System.out.println(trial1);

}
public static void main(String args[]){
replaceStr();
}
}
 
Fernando Dominguez
Ranch Hand
Posts: 111
Eclipse IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your interest.

replaceAll works well with (') quote,

but does not work with (�) spanish accent.

Thanks
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check if this helps

String cadena2 = "";
String cadena = "asdf�";
char c = 0xB4;
cadena2 = cadena.replaceAll(""+c,"");
System.out.println("cadena2 : "+cadena2);

I am not sure if this is the character code you have stated.

One URL that can be of help is
http://www.alanwood.net/demos/ansi.html

If checked already, please ignore

Thanks
 
Fernando Dominguez
Ranch Hand
Posts: 111
Eclipse IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It worked.

Many Thanks.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, i'm confusing about what you said, because java replaceAll() method working fine for me to replace these characters.



Result

D:\>java TestString
Before : Test 1 = replace'
After : Test 1 = replace
Before : Test 2 = replace┤
After : Test 2 = replace

Any idea why it work for me? I'm using JDK 1.6.0.07
 
Fernando Dominguez
Ranch Hand
Posts: 111
Eclipse IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you working on a windows machine?

I am working on an UNIX machine
I tried the "original" replaceAll on a windows machine and It worked.

So problem could be the way that both OS/editors uses the caracters.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Fernando Dominguez:
I notice that � this character does not exits in the ascii code, � � exits in the extended ascci code but not � alone.

It is in Unicode; look in Latin-1; its code number is 0x00b4.
 
Yong Mook Kim
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Fernando Dominguez:
Are you working on a windows machine?

I am working on an UNIX machine
I tried the "original" replaceAll on a windows machine and It worked.

So problem could be the way that both OS/editors uses the caracters.




Yes, i tested on windows platform. Thanks for info. I will be careful on my UNIX production server when dealing with special characters.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is peculiar; Java supports the whole of Unicode, and it is usually only a problem on Windows because the Windows command prompt doesn't support special characters. I don't use Unix, but the special character support on Linux which is similar to Unix is usually better than on Windows.
 
vipin jos
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you check what is the value you are getting for the following in Windows and Unix?

System.out.println(""+Integer.toHexString((int)'�'));

In windows I get "b4"
0xb4 is the character code.
 
Fernando Dominguez
Ranch Hand
Posts: 111
Eclipse IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for being so late.

I get b4 on my eclipse console on a debian linux.

Bye
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
b4? Are we playing Bingo?

Please Use Real Words.
 
vipin jos
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob,

I think Fernando meant character "0xb4" when he mentioned "b4". Not "before".

Thanks,
Vipin
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, you're right. I missed your post when I read his

My apologies.
reply
    Bookmark Topic Watch Topic
  • New Topic