The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Java subscript/superscript help
Discuss Java subscript/superscript help in the Java Help forum on Dev Shed. Java subscript/superscript help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 5th, 2012, 09:18 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 7
Time spent in forums: 1 h 7 m 12 sec
Reputation Power: 0
|
|
|
Java subscript/superscript help
Hey guys, Impossible4 here, I"m trying to find a way to make a virtual database of a periodic table, most of which I have covered, however I need a simple way of sub scripting string and integer variables. please help me!
|

November 5th, 2012, 10:52 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
Can you post some code examples of what you are trying to do?
The String class has methods for getting at sub parts of the string.
I don't know what you mean by "sub scripting integer variables".
You can get at bits in an int variable by using the AND (&) operator and shifting.
|

November 6th, 2012, 01:40 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 7
Time spent in forums: 1 h 7 m 12 sec
Reputation Power: 0
|
|
|
alright, well say you have beryllium and Nitrogen, the beryllium has a charge of +2, and nitrogen -4, so when combined, they would be Be(subscripted 4)N(subscripted 2)
|

November 6th, 2012, 02:49 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
What you posted looks like notation for chemistry. I don't understand chemistry, so you'll need to show what you want to do in a java program.
|

November 7th, 2012, 09:06 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 7
Time spent in forums: 1 h 7 m 12 sec
Reputation Power: 0
|
|
|
That is exactly what I want to do. I need the 2 and the 4 subscripted, but not as strings so they can be changed. It has nothing to do with chemistry, code wise, it just means I want to have the numbers subscripted.
|

November 7th, 2012, 10:19 AM
|
 |
Java Junkie
|
|
Join Date: Jan 2004
Location: Mobile, Alabama
|
|
Quote: | Originally Posted by impossible4 That is exactly what I want to do. I need the 2 and the 4 subscripted, but not as strings so they can be changed. It has nothing to do with chemistry, code wise, it just means I want to have the numbers subscripted. |
Do you just want them subscripted when printing? You could do that by displaying strings as HTML.
|

November 7th, 2012, 10:34 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | I want to have the numbers subscripted. |
Are you talking about the contents of a String? You want to use characters in a String that will display as subscripts.
Try asking Google for the Unicode values for the characters you want.
Last edited by NormR : November 7th, 2012 at 10:36 AM.
|

November 7th, 2012, 06:15 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 7
Time spent in forums: 1 h 7 m 12 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by NormR Are you talking about the contents of a String? You want to use characters in a String that will display as subscripts.
Try asking Google for the Unicode values for the characters you want. |
ah ok, but do you seriously think I haven't tried that? should there not be an easy way to do this? I've wasted at least 3 days on this already.
|

November 7th, 2012, 06:45 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
Not many people print characters that are not in the basic ASCII character set.
What did you find for Unicode character values for the characters you want to print/display? What have you tried?
|

November 8th, 2012, 05:40 PM
|
 |
Contributing User
|
|
Join Date: May 2004
Location: Superior, CO, USA
|
|
Quote: | Originally Posted by impossible4 ah ok, but do you seriously think I haven't tried that? |
No, I don't. It took me about 2 minutes:
java Code:
Original
- java Code |
|
|
|
public static void main ( String[] argv ) { String subScript = "Be\u2084N\u2082"; System. out. println( "the string is \"" + subScript + "\"" ); } }
As my Google search revealed, superscript characters are in the x2070 to x2079 range and subscript are in the x2080 to x2089 range. However, the giant caveat is that whatever font set you are using must have those characters in it, otherwise it will display some junk character. On my Ubuntu command line, for example, not all of the superscript characters are represented.
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|