aspose file tools*
The moose likes Java in General and the fly likes Ignore directional unicodes while comparing the strings. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Ignore directional unicodes while comparing the strings." Watch "Ignore directional unicodes while comparing the strings." New topic
Author

Ignore directional unicodes while comparing the strings.

Owais Zahid
Greenhorn

Joined: Nov 11, 2009
Posts: 21
I want to sort the list of strings. Some of the string can have directional unicode at the start and end of the string (like RTL unicode \u202B). I tried to use string compare but its not giving me the correct result. For example:

["A", "B", "C", "\u202BA"]

I want the sort method to sort like

A
\u202BA
B
C

Question: I heard about RuleBasedCollator. What rule i need to add in the RuleBasedCollator to have the desired sorting ? Is there any rule to ignore the list of characters all together ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

So basically you want to ignore the U+202B character entirely, because it's not really a "character", more like an instruction for layout by fonts? Well, I had a quick look at the API docs for RuleBasedCollator and I did see something about "ignorable characters". So yes, RuleBasedCollator looks like it might work for your requirement.
Owais Zahid
Greenhorn

Joined: Nov 11, 2009
Posts: 21
Thanks for the reply. Can you tell me what rule i can add to make this character ignored while sorting and comparing ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ignore directional unicodes while comparing the strings.
 
Similar Threads
ClasscastException in Collections.sort()
characters can not be displaied for codes between 0 and 65,535
Creation of char type during runtime
How to get unicode for a character?
Case-Sensitive sorting using Collator