Results 1 to 9 of 9

Thread: string-int-char

  1. #1
    mdhmdh100 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    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
    SRaith is offline Member
    Join Date
    Oct 2011
    Posts
    14
    Rep Power
    0

    Default Re: string-int-char

    1. Parse each to an int
    2. Cast them to char

    Example:
    Java Code:
    public class StringToChar {
        public static void main(String[] args) {
    	String[] s = {"104", "105", "103"};
    	
    	for(int i = 0; i < s.length; i++) {
    	    System.out.println((char)(Integer.parseInt(s[i])));
    	}
        }
    }

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: string-int-char

    Cross posted at string-int-char

  4. #4
    mdhmdh100 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: string-int-char

    Quote Originally Posted by SRaith View Post
    1. Parse each to an int
    2. Cast them to char

    Example:
    Java Code:
    public class StringToChar {
        public static void main(String[] args) {
    	String[] s = {"104", "105", "103"};
    	
    	for(int i = 0; i < s.length; i++) {
    	    System.out.println((char)(Integer.parseInt(s[i])));
    	}
        }
    }
    i have a string , not a string array . thank you for yor consideration but my problem is not solved .

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: string-int-char

    Um, then use the code supplied and modify it for your requirements (which did imply a String[]).
    Or are you expecting someone to write this for you?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    mdhmdh100 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: string-int-char

    Quote Originally Posted by Tolls View Post
    Um, then use the code supplied and modify it for your requirements (which did imply a String[]).
    Or are you expecting someone to write this for you?
    i m tryng

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: string-int-char

    Then show us what you;ve tried and where it is going wrong.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Join Date
    Feb 2012
    Location
    Delhi, India
    Posts
    5
    Rep Power
    0

    Default Re: string-int-char

    give this complete step by step process a try..
    1. first split that string using split() method of String class. splitting should be done using comma as separator(NEED TO B PAASED AS AN ARGUMENT TO split() method). this will return you a String Array.
    2. But now u know, your first n last String in String Array has few unwanted part i.e. opening square bracket "[" in first string and closing square bracket "]" in last string. so remove these using subString method of string and save it at their location. Now u have your input String Array ready...
    3.parse each to int
    4. cast them to char (refer above posted code for step 3 n 4)
    I can give u complete code, but i also want u to give it a try first.............. so that a day will come tomorrow, when u will be resolving my JAVA issuesssssss..ALL THE BEST :-)

  9. #9
    mdhmdh100 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: string-int-char

    Quote Originally Posted by vaec0.java@hotmail.com View Post
    give this complete step by step process a try..
    1. first split that string using split() method of String class. splitting should be done using comma as separator(NEED TO B PAASED AS AN ARGUMENT TO split() method). this will return you a String Array.
    2. But now u know, your first n last String in String Array has few unwanted part i.e. opening square bracket "[" in first string and closing square bracket "]" in last string. so remove these using subString method of string and save it at their location. Now u have your input String Array ready...
    3.parse each to int
    4. cast them to char (refer above posted code for step 3 n 4)
    I can give u complete code, but i also want u to give it a try first.............. so that a day will come tomorrow, when u will be resolving my JAVA issuesssssss..ALL THE BEST :-)
    thank u for no spoooon feeed

Similar Threads

  1. Help with char and string
    By mehnihma in forum New To Java
    Replies: 13
    Last Post: 11-01-2011, 11:06 PM
  2. check a string char by char
    By Sotsiak in forum New To Java
    Replies: 2
    Last Post: 10-23-2010, 09:24 PM
  3. Char to Bit String
    By Krooger in forum New To Java
    Replies: 2
    Last Post: 01-29-2010, 02:26 AM
  4. char to string
    By kian_hong2000 in forum New To Java
    Replies: 2
    Last Post: 08-25-2008, 01:51 PM
  5. Help with, String, Char
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 02:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •