Convert from char to ASCII code

anyone can advice me on this program why the conversion cannot be done? Thank in advance.
String charInput = JOptionPane.showInputDialog (null, "Enter a character", "Finding ASCII code", JOptionPane.QUESTION_MESSAGE) ;
answer = Integer.parseInt (charInput) ;

Try this code out:
import javax.swing.JOptionPane;
public class Crap {
    public static void main (String[] args) {
        String charInput =
                JOptionPane.showInputDialog (null,
                "Enter a character", "Finding ASCII code",
                JOptionPane.QUESTION_MESSAGE) ;
        JOptionPane.showMessageDialog (null, charInput, "Collected Data",
                JOptionPane.INFORMATION_MESSAGE );
//        answer = Integer.parseInt (charInput) ; //<-- What datatype?
        String answer = "You never declare the data type for you answer.\n" +
                "JOptionPane returns a string of what the user enters.\n" +
                "The first?  The last? Some other position?\n" +
                "A String != a character.\n" +
                "Which character of the string do you want to convert?\n" +
                "You need to do a lot more work on this problem.";
        JOptionPane.showMessageDialog (null, answer,
                "The Java Compiler hates your code because...",
                JOptionPane.OK_OPTION, null);
}http://leepoint.net/notes-java/GUI/containers/20dialogs/10joptionpane.html
Cheers !
JJ

Similar Messages

  • Convertion from CHAR to ASCII

    Hello,
    Please tell me how we can change a character to ASCII foormat.
    Points will definitltely be given to the useful answers.
    thanks.

    Hi,
    Check following link:
    [http://www.sap-img.com/abap/how-can-i-get-ascii-value-of-any-letter.htm]
    or
    Check function module:
    SCP_TRANSLATE_CHARS
    Regards,
    Harsh.

  • Convert char to ascii code and vice versa

    HI
    Is there any function module to convert char to ascii code and vice versa.
    Thanks in advance

    Hi,
    be careful if you have unicode running in your system. URL_ASCII_CODE_GET is platform-dependent so it will return the internal HERX representation of the character in your system - which is hopefully and in most cases ASCII.
    Under unicode, we use double-byte characters here. I tried this function and the result CHAR_CODE is '00' regardless what character I specify for TRANS_CHAR. But the coding is so simple I corrected resultig in this sample code:
    [P]
    convert p_form to ASCII (internal) representation
      DATA:
        l_ofs TYPE syfdpos,
        l_len TYPE sy-linsz,
        l_ascii TYPE i.
      FIELD-SYMBOLS:
        <x> TYPE x.
      l_len = STRLEN( p_ascii ).
      DO l_len TIMES.
        l_ofs = sy-index - 1.
        ASSIGN p_ascii+l_ofs(1) TO <x> CASTING.
        l_ascii = <x>.
        WRITE: l_ascii.
      ENDDO.
    [/P]
    Here, for each character of string p_ascii, the internal (ASCII) representation is determined and written to the output list.
    Regards,
    Clemens

  • Convert from char to int

    hey
    I've an input string ("1234")
    What i need to do is to fill a matrix 2*2 with the input string.
    I thought about running over the string, and by str.charAt(ind) to get a needed charters, but the question is ho do i convert charAt result to int?
    tanx

    igalep132 wrote:
    hey
    I've an input string ("1234")
    What i need to do is to fill a matrix 2*2 with the input string.
    I thought about running over the string, and by str.charAt(ind) to get a needed charters, but the question is ho do i convert charAt result to int?
    tanxThat's kinda vague. Do you mean convert '1' into the integer value 1 or convert '1' into the ASCII integer value of 49?
    Here's how to do the first:
    String one = "8";
    String two = "3";
    String numbers = "0123456789";
    int oneInt = numbers.indexOf(one);
    int twoInt = numbers.indexOf(two);
    System.out.println("oneInt = " + oneInt);
    System.out.println("twoInt = " + twoInt);If you meant the latter then ...
    char c = 'c';
    int cInt = (int)c;

  • Convert from char* to unsigned char*

    Hi, I try compile example from: http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14294/relational.htm#i1000940
    in Visual C++ and I have problem with:
    const string userName = "SCOTT";
    because string is defined as unsigned char* and "SCOTT" is char*, is any function to convert from type char* to type unsigned char* ?

    I'm apologize for this stupid question, answer is very easy:
    const string userName = (const unsigned char*) "SCOTT";

  • Convertion from Char to Hex

    Hi Experts,
    I have a requirement to convert char type to Hex type.
    I have two structures. one is Character type and other is hex type like below.
    data: v_hex(300) type h,
            v_char(300) type c.
    When we move v_char(300) to v_char(300), it is working fine in 4.6 system.
    But it is giving unicode error in ECC 6.0. So i have changed the statement to v_hex = v_char.
    There is no syntax error but it is not converting the same.
    Please post your replies. Thanks in advance.

    REPORT  ZSRK_039                                .
    DATA: V_HEX(300) TYPE X,
          V_CHAR(300) TYPE C.
    V_CHAR = 'Test'.
    PERFORM CHAR_TO_HEX_CONV USING V_CHAR
                             CHANGING V_HEX.
    WRITE : / V_HEX.
    *&      Form  CHAR_TO_HEX_CONV
          text
         -->P_V_CHAR  text
         <--P_V_HEX  text
    FORM CHAR_TO_HEX_CONV  USING    CH TYPE C
                           CHANGING CH1 TYPE X.
      FIELD-SYMBOLS : <FS_TR> TYPE X.
      ASSIGN CH TO <FS_TR> CASTING TYPE X .
      CH1 = <FS_TR>.
    ENDFORM.                    " CHAR_TO_HEX_CONV

  • Check a convertion from CHAR TO NUMC

    Hi,
    I import a flatfile into a structure that contains only CHAR-fields. Then I make a TRY-CATCH construct for every field in P,I,F,N..-datatypes to check if the data is correct.
    P,I,F raise a CONVERT-Exception that i can handle.
    A move to N-field raise no exception but put a wrong values to the N-field.
    Example:
    Charfield contains ' 1  1 0000', N-field is '110000'.
    A compare in the program like
    IF C-Field <> N-Field raise a exception that can't be catched by TRY-Catch.
    How can i check if the field is correct?
    Anybody understand me and have an idea?
    Regards,
    Stefan

    Hi Christian and Rich,
    thank you for your fast reply.
    I've written one TRY method that has a import-parameter with TYPE ANY and a import-parameter for the target field.
    The target field can be everything like P,I,F,N,C,D.
    The method checks if the value can be converted into the target field and avoid a shortdump, when the flatfile contains bad data.
    So I have to get the type by
    cl_abap_typedescr=>describe_by_data
    and then make your suggested Conatins-only-check if it is a
    cl_abap_typedescr=>typekind_num
    Thanks,
    Stefan

  • Convert from CHAR to HEXA

    Hi Experts ,
    i am working  in Upgradation project. In one of the program i  came   across  Moving  Char  value to Hexa value. More over , the char(  CHAR(1)  )   value is passing dynamically to Hex.
    Is there any function module to solve this issue. i got  CHAR_HEX_CONVERSION  but it is not working.
    Thank you.
    Regards,
    Kiran.

    Hello,
    Does the method CONVERT of class CL_ABAP_CONV_IN_CE help ?
    A few links which might interest you :
    [Conversion xstring to string|Conversion xstring to string]
    [http://help.sap.com/saphelp_nw70/helpdata/en/ba/78d3c747b24546ab1c1499a054d8a5/content.htm|http://help.sap.com/saphelp_nw70/helpdata/en/ba/78d3c747b24546ab1c1499a054d8a5/content.htm]
    BR,
    Suhas
    Edited by: Suhas Saha on Jan 21, 2010 5:41 PM

  • Need you help !!! -- Convertion from Char to Date

    Dear experts:
    I am new to abap and here is one thing need your help:
    Currently I have a char type field defined in the source table, after I retrive this field into my work area, I need to convert it to Date type and then calculate the last day of this date.
    for example: WA_TEST-CHAR = '20100801'. This value in orignal ECC table is char type.
    Then How can I convert this value to a date type, and calculate its last day?
    My expected result is "20100731".
    BTW, does anybody know how to convert a date type field to a number type field like To_number() or something?. If I need to get the period between 2 different date, how can I get this?
    Any post will be appreciate and thank you all in advance!
    Best Regards
    Tim
    Moderator message: sorry, date conversion and date calculation are very basic and FAQs, please search for available answers, also read ABAP online documentation.
    locked by: Thomas Zloch on Aug 23, 2010 9:56 AM

    Hi,
    For your question:
    BTW, does anybody know how to convert a date type field to a number type field like To_number() or something?. If I need to get the period between 2 different date, how can I get this?
    use this FM FIMA_DAYS_AND_MONTHS_AND_YEARS.
    regards,

  • Convertion from char to raw

    HI all,
    I have to convert a char255 to raw255. Is there any methods/function module that can do this.
    Regards
    Ravish

    Hi,
    try this FM
    Unicode - Konvertierung SOLI in SOLIX
    CALL FUNCTION 'SO_SOLITAB_TO_SOLIXTAB'
    EXPORTING
    ip_solitab = gt_compressed_list[]
    IMPORTING
    ep_solixtab = gt_pdf_hex[].
    Regards

  • Problems to get the correct Ascii code from a char

    We need convert each of the chars into a string to a short number, send it to another application and then convert again each short to a char, and so retrieve the original string.
    We have tested this piece of code to convert from char to short and again from short to char:
    private static BufferedReader stdin = new BufferedReader (new
    InputStreamReader(System.in)); private static String user_key;
    String texto = "aeiounAEIOUN0123456789" ;
    for (int aux=0; aux<texto.length(); aux++)
    c = texto.charAt(aux); s = (short)c;
    System.out.printin ("char = '" + c + "' short = " + s);
    // Each time that the user press a key, we process a new char
    // from the String.
    try {user_key = stdln.readLine();} catch (lOException io) {}
    And when the program process the � (ascii 164) and � (ascii 165) chars, it does not work right.
    The output is:
    char='?' short=241
    char='D' short=209
    Instead, if we read directly from the keyboard, this code works right:
    while (true)
    try {user_key = stdln.readLine();} catch (lOException io) {}
    c = user_key.charAt(0); s = (short)c;
    System.out.printin ("char = '" + c + "' short = " + s);
    And we get these outputs when we press the � (ascii 164) and � (ascii 165) keys:
    char='?' short=164
    char='?' short=165
    Please can you say me how can I change the first piece of code to it works right with the 'n' and 'N' chars?
    Thanks in advance
    Jos?

    Run your application with "java -Dfile.encoding=CP850 ClassName", or change the encoding on run time to CP850 by using the appropriate constructor of InputStreamReader.
    I recommend the first option since the problem doesn't exist outside the DOS console of Microsoft Windows. If you use the second approach your program wont be portable.

  • Convert char to ascii

    Hello,
    How can i convert a char to ascii, and ascii to char??
    thanks,
    Riss

    its quite simle really.
    // 199 is the ascii value for 'w';
    char doubleU = 119;
    System.out.println(doubleU);
    //or
    String doubleUString = "119";
    doubleU = (char) Integer.valueOf(doubleUString).intValue();
    System.out.println(doubleU);
    //to get the ascii value of a letter
    System.out.println(doubleU);
    doubleUString = "w";
    doubleU = doubleUString.charAt(0);
    System.out.println(doubleU);
    System.out.println((int) doubleU);

  • Extended Ascii Code in Swing

    Hi master,
    I have found some viewing extended ascii code in Swing. The palteform I used is Windows Me.
    It is not viewing properly for some of chars with ascii code more than 127 to 255.
    Any idea would be appreciate.
    Thanks in advance!

    Hi,
    This character is special one, so you can't print it out. In SAP all special charcter which can't be printed are replaced with placeholder #.  They are intended to do theri special purpose in flat file, once you open it.
    Do the following:
    - use fm HR_KR_XSTRING_TO_STRING to convert xstring with value  '1F' (30 decimal value) to string
    - write this string to certain place in internal string table (where you want later use it in the file)
    - download this table as to file
    - special character will do its purpose in text file
    This is the same functionality as you would be placing Line Feed (0x0A - 10 dec). It would be shown as # but once you open downlaoded file you don't see hash # anymore, but you see that new line in that place.
    Hope this is clear
    Regards
    Marcin

  • Need help with converting characters to ASCII code

    Hey. Im trying to write a program to make Caesar Ciphers by random numbers. This cipher must also wrap from front to end of ASCII code, so that if, for example, the character being ciphered is Z and its being modified by +3, the result ciphered character is not "]", but "c".
    Im planning on reading the text that the user inputs (using ConsoleIO) into a string and then seperating each character into a character[]. Then, i would like to find the ASCII code of each character and print out the ASCII code character of the old ASCII code + the modifier.
    So far, this is what i have (sorry for the length, i like to space things out so that its easier on the eyes and more organized... X-( ... ):
    public class EvanFinalB {
         static ConsoleIO kbd = new ConsoleIO();
         static String enteredPhrase;
         static int phraseLength;
         public static void main(String[] args)
              System.out.println("Enter a phrase and this program will cipher it into a secret message.");
              System.out.println("/nEnter your phrase here:");
              //read phrase
              enteredPhrase = kbd.toString();
              //find length of entered text
              phraseLength = enteredPhrase.length();
              //declare arrays for the individual characters of the entered text and the ciphered characters
              char[] enteredChar = new char[phraseLength + 1];
              char[] cipheredChar = new char[phraseLength + 1];
              //loop converting of entered text into seperate characters
              for(int x = 1; x <= phraseLength; x++)
                   enteredChar[x] = enteredPhrase.charAt(x);
                   cipheredChar[x] = cipher(enteredChar[x]);//call cipher() method to find new ciphered character
         //wrap from front to end of ASCII code
         static char cipher(char enteredChar)
              //choose random number to cipher message by
              int modifier = (int)(Math.random() * 26) + 1;
              if(enteredChar + modifier > 90)//90 is the ASCII code for "Z" which is the last capital letter
                   cipheredChar = (97 + (modifier - (90 - enteredChar)));//97 is the ASCII code for "a" which is the first lower case letter
              return cipheredChar[1];
    }The program is obviously in its early stages but (i started creating it today actually), if there is a simple method or anything that i can use to find the ASCII value of a character in order to use enteredChar so that 'enteredChar' is equal to the ASCII code of the new ciphered character, please help me out...Thanks
    P.S. If there's an easier way to go about creating a program for Caesar Ciphers, let me know.

    The following code is from my Java textbook Big Java by Cay Horstmann. It is not my code and it's just to guide you in your own cipher.
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.IOException;
       This class encrypts files using the Caesar cipher.
       For decryption, use an encryptor whose key is the
       negative of the encryption key.
    public class CaesarCipher
          Constructs a cipher object with a given key.
          @param aKey the encryption key
       public CaesarCipher(int aKey)
          key = aKey;
          Encrypts the contents of a stream.
          @param in the input stream
          @param out the output stream
       public void encryptStream(InputStream in, OutputStream out)
             throws IOException
          boolean done = false;
          while (!done)
             int next = in.read();
             if (next == -1) done = true;
             else
                byte b = (byte) next;
                byte c = encrypt(b);
                out.write(c);
          Encrypts a byte.
          @param b the byte to encrypt
          @return the encrypted byte
       public byte encrypt(byte b)
          return (byte) (b + key);
       private int key;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.Scanner;
       This program encrypts a file, using the Caesar cipher.
    public class CaesarEncryptor
       public static void main(String[] args)
          Scanner in = new Scanner(System.in);
          try
             System.out.print("Input file: ");
             String inFile = in.next();
             System.out.print("Output file: ");
             String outFile = in.next();
             System.out.print("Encryption key: ");
             int key = in.nextInt();
             InputStream inStream = new FileInputStream(inFile);
             OutputStream outStream = new FileOutputStream(outFile);
             CaesarCipher cipher = new CaesarCipher(key);
             cipher.encryptStream(inStream, outStream);
             inStream.close();
             outStream.close();
          catch (IOException exception)
             System.out.println("Error processing file: " + exception);
    }

  • Convert JMS Headers from EBCDIC to ASCII when using JMS Bridge (WLS - WMQ)

    I have a Java app on Weblogic 11g using a Message Bridge to talk JMS with IBM Websphere MQ. The MQ server is running on IBM z/OS platform which uses EBCDIC encoding. I need to use the Weblogic message selector feature to filter messages on the bridge coming from Websphere MQ. But the JMS Headers of MSGs posted by WMQ are in EBCDIC format. How can I instruct MQ to convert the msg headers to ASCII before put on the bridge? Is there any flag on bindings config file? Or can I set some WMQ specific header before sending the msg on WLS side?
    Thanks in advance.

    Hi,
    Such option is not possible in weblogic but I think this property will help you with in MQ.
    Property - Convert EBCDIC newline
    Description - EBCDIC code pages contain a new line (NL) character that is not supported by the ASCII code pages (although some ISO variants of ASCII contain an equivalent). If messages are sent from a system that uses EBCDIC code pages (for example, a z/OS system) to a system that uses ASCII, you can control how the EBCDIC newline character is converted into ASCII format.
    The default value is NL_TO_LF, which means that the EBCDIC NL character (X'15') is converted to the ASCII line feed character LF (X'0A') for all EBCDIC to ASCII conversions. To convert the EBCDIC NL character according to the conversion tables on your operating system, click TABLE. Note that the results of a TABLE conversion can vary from platform to platform and from language to language; even on the same platform the results might vary if you use different coded character set identifiers (CCSIDs). To convert ISO CCSIDs using the TABLE method and use the NL_TO_LF method for all other CCSIDs, click ISO.
    Registry Stanza Key - ConvEBCDICNewline
    Also, the MQSeries (not MQSC) adapter provides the data conversion property may handle this conversion as well.
    Regards,
    Kal

Maybe you are looking for