#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    7
    Rep 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!
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    7
    Rep 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)
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    7
    Rep 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.
  10. #6
  11. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    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.
  12. #7
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    7
    Rep Power
    0
    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.
  16. #9
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    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?
  18. #10
  19. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    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:
    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.

    Comments on this post

    • Annie79 agrees

IMN logo majestic logo threadwatch logo seochat tools logo