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;

Similar Messages

  • Convert from String to Int

    Hi,
    I have a question.
    How do I convert from String to Integer?
    Here is my code:
    try{
    String s="000111010101001101101010";
    int q=Integer.parseInt(s);
    answerStr = String.valueOf(q);
    catch (NumberFormatException e)
    answerStr="Error";
    but, everytime when i run the code, i always get the ERROR.
    is the value that i got, cannot be converted to int?
    i've done the same thing in c, and its working fine.
    thanks..

    6kyAngel wrote:
    actually it convert the string value into decimal value.In fact what it does is convert the (binary) string into an integer value. It's the String representation of integer quantities that have a base (two, ten, hex etc): the quantities themselves don't have a base.
    To take an integer quantity (in the form of an int) and convert it to a binary String, use the handy toString() method in the Integer class - like your other conversion, use the one that takes a radix argument.

  • 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";

  • Fact columns Datatype is changing from char to int in OBIEE 11g

    Hi ,
    I am taking measure columns - "product description","tot cost" against a dimension "project name" .
    I am generating this report in a planing form and OBIEE .
    in planing form :
    product description tot cost
    project name
    P1 A 1500
    p2 B 1700
    p3 C 1800
    in obiee report :
    product description
    project name
    P1 16 1500
    p2 17 1700
    p3 19 1800
    Somehow , measure's datatype are getting changed from char to number , in OBIEE report.
    By default , the data type for all fact's is Double .I tried changing that to varchar , but result is same .
    Do I need to change anything in physical layer / RPD .
    OBIEE version : 11.1.1.6
    Essbase version : 11.1.2

    Hi ,
    Thanks for your reply . To confirm , the data type of product description column is "double" in essbase .
    I found out ,thers's a RDBMS table , consisting of two columns - ID, text value . where product description's are in text value's with the corresponding ID's(integer values) .
    Now , when I am creating a form in planning , its fetching the text values of product description (there's some inbulit setting's available for this in plannng) .
    However , in obiee its fetching the ID values of product description .
    So ,
    1. Is there any similer setting I can do for OBIEE , so that it's fetches only text value's of product description .
    2. If not , then I have to join the essbase fact table with this RDBMS table . I am not sure how to do it .

  • Leading Zeroes are lost when convert from string to int

    What I'm trying to do is simple yet the solution has seemed difficult to find.
    I have a system that requires 4 digit numbers as "requisitionNo". The system uses JSPs and accepts the 4 digit number that the user inputs (fyi - duplicate handling is already managed). The input number (rNumber) is of STRING type and in the action (using struts) is converted to an int:
    int requisitionNo = Integer.parseInt(rNumber);At that very line the issue is that when the user inputs a number with leading zeros such as: "0001" the 3 leading zeros are chopped off in the INT conversion. The application validation kicks in and says: "A 4 digit number is required" which is by design. The work around has been that the user has been putting in number that start with 9's or something like that, but this isn't how the system was intended to be used.
    How do I keep the leading zeroes from being lost instead of saving a number "1" to the database how do I keep it saving "0001" to the database? Would I just change everything to STRING on down to the database? or is there another number type that I can be using that will not chop off the leading zeroes? Please provide short code references or examples to be more helpful.

    Yeah, I have to agree here that leading zeroes make no sense. I figured that out when I started to look into this problem. The only requirement that exists is that the user wants it to be a 4 digit number due to some other requirement they have themselves.
    So what I'm gathering from what I've read in the responses thus far is that I should change the validation a bit to look at the STRING for the 4 required digits (which are really 4 characters; maybe I should add CLIENT side numeric validation; currently its doing server side numeric/integer validation; or maybe change up the server side validation instead???) and if they are ALL GOOD then let the application save the int type as it wants to. IE: Let it save "0001" as just "1" and when I come back to DISPLAY this saved number to the user I should append the string of "000" in front of the 1 for display purposes only? Am I understanding everyone correctly?

  • 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

  • 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

  • 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.

  • Converting chars to ints, get a strange math error...

    Here's the code I have.
    import java.util.*;
    public class Encryption {
         public static void main(String[] args) {
              Scanner sc1 = new Scanner(System.in);
              System.out.print("Enter a four-digit integer to be encrypted: ");
              String encrypt = sc1.nextLine();
              char a = encrypt.charAt(0);
              char b = encrypt.charAt(1);
              char c = encrypt.charAt(2);
              char d = encrypt.charAt(3);
              int as = new Integer(a).intValue();
              int bs = new Integer(b).intValue();
              int cs = new Integer(c).intValue();
              int ds = new Integer(d).intValue();
              int codea = (as + 7);
              while (codea > 9) {codea = codea - 10;}
              int codeb = (bs + 7);
              while (codeb > 9) {codeb = codeb - 10;}
              int codec = (cs + 7);
              while (codec > 9) {codec = codec - 10;}
              int coded = (ds + 7);
              while (coded > 9) {coded = coded - 10;}
              int finala = codec;
              int finalb = coded;
              int finalc = codea;
              int finald = codeb;
              String encrypted = ("" + finala + "" + finalb + "" + finalc + "" + finald + "");
              //System.out.println ("The encrypted number is " + encrypted + ""); set aside while debugging
              System.out.println(" " + a + " " + b + " " + c + " " + d + " ");
              System.out.println(" " + as + " " + bs + " " + cs + " " + ds + " ");
    }Now here's the console.
    Enter a four-digit integer to be encrypted: 1234
    1 2 3 4
    49 50 51 52
    When I went from char to int, 1 became 49, 2 became 50, etc...how did this happen?

    class Fubar1
        public static void main(String[] args)
            System.out.println("'1' = " + '1'); // prints the char
            System.out.println("(int)'1' = " + (int)'1'); // prints the ASCII (unicode?) number that represents that char
    }

  • Convert from int to char

    Hi,
    How can I convert from an int to char?

    The challange is to convert from int to String without using any API or automatic conversionWoah, what a challenge ! Why ?
    Anyway, what about a recursive call and switch statement. Something likepublic String intToString(int n) {
        if(n<0) {
            return "-"+intToString(-n);
        if(n<10) {
            return getStringDigit(n);
        else {
            return intToString(n/10) + getStringDigit(n%10);
    private String getStringDigit(int n) {
        switch(n) {
            case 0:
                return "0";
            // etc.
    }

  • Convert from int to String

    Hi, may i know how to convert from int to String??
    For instance, i've>>
    int i = 0;
    i++;
    String temp = i.toString();
    [Need to convert the int to String here. Am i doing the convertion correctly?? Pls correct me. Thanks!]

    Hi, may i know how to convert from int to String??
    For instance, i've>>
    int i = 0;
    i++;
    String temp = i.toString();
    [Need to convert the int to String here. Am i doing
    the convertion correctly?? Pls correct me. Thanks!]String temp = "" + i;

Maybe you are looking for

  • Line overlapping row in report

    I am doing maintenance in a report that runs to a time when small executes properly, but when runs for a whole month, about 165,000 pages, a dotted line (uline) overwrites the record. Someone already seen something similar before and solved. Example

  • Clearing process in SAP

    Dear Experts, I am quiet confused about this clearing process in SAP. For example a cash discount in SAP is posted with the following entry 01 Cust a/c 15000 40 Cash disc a/c 3000 50 Sales or revenue a/c 18000. The above open item in the customer acc

  • How can I sort memos alphabetically?

    I have over 300 memos and want them to be sorted alphabetically. This way, it is easier for me to find a particilar memo or note. How can I set Memo this way?

  • HANA Procedure with parameter in create part

    Hi! I have a problem with creating a HANA procedure. My procedure looks like this: CREATE PROCEDURE myProcedure ( IN ToDate TIMESTAMP) LANGUAGE SQLSCRIPT AS d1 TIMESTAMP; BEGIN d1:= :ToDate; CREATE LOCAL TEMPORARY TABLE #Avst AS ( SELECT * FROM ITR1

  • Output Type in Sales Order

    Hi All.. Output type is not automatically selecting/ coming in sales order.. Condition record has been maintained in VV11 and I have also checked the configuration which seems okay to me.. Pls suggest where is the problem? thanks in advance