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.
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".
Never ascribe to malice that which can be adequately explained by stupidity.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
4
posted
2
What is the Unicode value of that apostrophe? Is it \u0027 (') or \u2019 (’)? If you simply push the key, you usually get \u0027.
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
posted
0
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.
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: 32611
4
posted
0
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 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
posted
0
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: 12266
1
posted
0
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.
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.