Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: string-int-char

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default string-int-char

    i have a string as below

    string s =[104, 105, 103];

    i want to extract the integer values and show it as character in Ascii format e.g

    104=h
    105=i
    103=g

    your advisez are appreciated .


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: string-int-char

    Cross posted at string-int-char

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    106
    My Mood
    Yeehaw
    Thanks
    8
    Thanked 11 Times in 11 Posts

    Default Re: string-int-char

    (what is a cross post? do we post here or there?)

    this code doesn't compile.
    1. Strings are objects, and that means they start with a capital.
    2. Strings can't be initialized like that ([104, 105, 103])
    string s =[104, 105, 103];

    This code would work,
    AKA: String s = "104, 105, 103";

    About converting strings to characters.
    Java Convert Character to String


    1) it seems far more useful to have an int array for this problem(up to you to understand what the teacher wants)
    int[] myString = {104, 105, 103};


    2) then all you have to do is use a "char" variable to convert it.
    char oneLetter = (char)myString[0]; (this converts 104 into a char, which is 'h')

    Hope this helps,
    Jonathan
    Last edited by JonLane; February 25th, 2012 at 01:38 PM. Reason: hyperlink fix

Similar Threads

  1. Char to String - Gender method.
    By ibby50 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 2nd, 2012, 12:42 PM
  2. Go through string one char at a time
    By joshft91 in forum Java Theory & Questions
    Replies: 7
    Last Post: April 18th, 2011, 12:19 AM
  3. [SOLVED] String Matcher finding only char not a whole string
    By Kakashi in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 18th, 2011, 09:58 AM
  4. Convert CHAR to STRING
    By fh84 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 29th, 2009, 09:21 PM
  5. Need help with concatenizing char? to string?
    By bh-chobo in forum Java SE APIs
    Replies: 3
    Last Post: October 16th, 2009, 08:40 AM