Ask Experts Questions for FREE Help !
Ask
    inout's Avatar
    inout Posts: 1, Reputation: 1
    New Member
     
    #1

    May 4, 2015, 05:11 AM
    Converting chars to digits and digits to one String
    I split a String to char convert every single char to a digit.Then I want to put all digits from the string given together in an array.Any idea how to do it?
    What I have done is I have a switch for converting chars to digits the output of every case gives me a digit but I want to have for the input String the output in digits .T
    George985's Avatar
    George985 Posts: 4, Reputation: 2
    New Member
     
    #2

    Jun 23, 2015, 02:50 AM
    Propably a little late answer, but, the thing you need is the function String.toCharArray().
    So what you would do is take the string you want, use the toCharArray function, then convert each char to digit and put in in the array.

    Code:
    String my_string = "random string";
    int[] digit_array = new int[my_string.toCharArray().length];
    int index = 0;
    for( char c : my_string.toCharArray() ) {
        digit_array[index] = char_to_digit_function(c);
        index++;
    }
    A full working example is attached as .txt file.
    Attached Files
  1. File Type: txt test.txt (434 Bytes, 84 views)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Arranging digits [ 3 Answers ]

Arrange the digits 1,2,3,4,5,6,7,8,9 into three 3 digit numbers such that their total is close to 1500.

The difference of the last two digits is less than one [ 1 Answers ]

The subtraction of the last two digits they are less than one

Getting the "Digits" [ 7 Answers ]

Threads merged Hmmm I like this guy and well everyone thinks that he obviously likes me but I am really shy and always have doubts like it'll be the end of the world if I tell him how I feel about him... And I would like to know how to and when to ask for his number and remember I am like...

How many 4 digits number formed of only odd digits are divisible by five [ 3 Answers ]

How many 4 digits number formed of only odd digits are divisible by five


View more questions Search