• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retain apostrophe in Collection object

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
Oracle Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Display it on a Java™ platform.
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic