permaculture playing cards*
The moose likes Java in General and the fly likes retain apostrophe in Collection object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "retain apostrophe in Collection object" Watch "retain apostrophe in Collection object" New topic
Author

retain apostrophe in Collection object

verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
I have a TreeSet of values. One value contains an apostrophe. When the contents of the TreeSet are listed, instead of an apostrophe, it displays another character. I tried changing the TreeSet to an ArrayList, with the same result. How do I get around this?



results:

DRAINS
IVÆS,
TUBES

I really need the output to match what I have listed above. Any tips are greatly appreciated. Thanks in advance.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11175
    
  16

This doesn't address your question, but does the IV own something? That's the only reason I can see why you would type "IV'S", as in "The IV's line to the bag".

If you are talking about more than one IV, it would be "IVs" or "IVS".


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
What is the Unicode value of that apostrophe? Is it \u0027 (') or \u2019 (’)? If you simply push the key, you usually get \u0027.
Eli Wood
Ranch Hand

Joined: Sep 04, 2008
Posts: 37

Campbell Ritchie wrote:What is the Unicode value of that apostrophe? Is it \u0027 (') or \u2019 (’)? If you simply push the key, you usually get \u0027.

You may be able to just use the Unicode value of the troublesome value. For example, if it's \u2019 your code would look like this:
verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
fred rosenberger: Thanks for the reply. Unfortunately, this data is dictated by the system. The presence of the apostrophe in the data is outside of my control. I have to accommodate it.

Eli Wood and Campbell Ritchie: I will be loading these values dynamically, so I won't be able replace the apostrophe with the Unicode value. I tried to do this programmatically:


which prints:

IVÆS,

so this didn't work. Did I use the regex above incorrectly?

Are there any other ways to make this work? This is urgent, so I appreciate your responses.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

I blame your command prompt. Most shells, including Windows' command prompt, can't display most characters that aren't extended ASCII.

verduka fox wrote:This is urgent

Please EaseUp. There is no "urgent" around here.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

verduka fox wrote:Are there any other ways to make this work? This is urgent, so I appreciate your responses.


At the command line? No. If you're writing a command-line application and you have to support characters outside of whatever your shell supports, you're out of luck.

But are you writing a command-line application? If you aren't, then don't use the shell to do that sort of testing. It just confuses things. Use whatever medium the application is targeting (Swing GUI, web app, whatever) to do that testing.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Rob Spoor wrote: . . . Most shells, including Windows' command prompt, can't display most characters that aren't extended ASCII. . . . .
That is why I thought they were using \u2019. But that would surely come out on Windows® as ?

Æ is \u00c6, and I can't find any sort of apostrophe that is C6, not even in EBCDIC.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Campbell Ritchie wrote:
Rob Spoor wrote: . . . Most shells, including Windows' command prompt, can't display most characters that aren't extended ASCII. . . . .
That is why I thought they were using \u2019. But that would surely come out on Windows® as ?

I wouldn't count on that. Applications like Word can handle it, Windows' command prompt is quite limited in what it can display. \u2019 is definitely not one of them.

Æ is \u00c6, and I can't find any sort of apostrophe that is C6, not even in EBCDIC.

When Windows' command can't print out the character, it can print out anything. For instance, if I print out both \u2019 and \u00c6 I get Æ and ã. Go figure!
verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
My code is actually running on WebSphere Portal on AIX. When it runs there, the apostrophe is displayed as a question mark '?' instead of an apostrophe. When I'm debugging this on Windows, Windows displays the apostrophe as Æ. In either case, the apostrophe I specify in the code is not displayed as such. How do I get the code when run to display what is actually written in the code?

PS Sorry for the urgent comment. I didn't mean to upset anyone.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I will be loading these values dynamically, so I won't be able replace the apostrophe with the Unicode value.


You should be able to replace those dispicable MS Word "smart" punctuation marks dynamically with regex.

I would use an editor capable to displaying hex values to see exactly what the bogus apostrophe code is.

Looking back at how I solved the problem, I used the String replace function - which is faster - like this:



When you find out what the "apostrophe" code is, just add a line.

Bill
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Display it on a Java™ platform.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

William Brogden wrote:Looking back at how I solved the problem, I used the String replace function - which is faster - like this:

I would actually not use String.replace but loop. Your code loops over the String 12 times, potentially creating 12 new Strings. One single loop will suffice:
As in your code, replacing another character is easy: just add one case statement with replacement.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: retain apostrophe in Collection object
 
Similar Threads
How to store a name in an arraylist?
Struts 2 Iterate tag not getting the customed format
brackets enclosure
Please Help: JList selectable options from 'name' field from each object in a HashMap
Migrating Project from java 1.4 to 1.5