Results 1 to 13 of 13
  1. #1
    maskanio is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default How do i put multiple charAt's in one char?

    char threeMorse = myMorse[2].charAt(0);

    this works, it returns the char at the 0 spot of this array spot which return 3

    What if I want to do something like char threeMorse = myMorse[2].charAt(0) + myMorse[2].charAt(1); <------This doesnt work but I want something similar to this logic

    Is this possible? Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do i put multiple charAt's in one char?

    Perhaps you should explain what you're trying to do in general terms, not in coding terms. What do you want to achieve with this code?

  3. #3
    maskanio is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: How do i put multiple charAt's in one char?

    I want to put the first two spots of an arrays data into one char

  4. #4
    maskanio is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: How do i put multiple charAt's in one char?

    It has some extra useless data after it that I dont need so I just want the first 2 spots

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do i put multiple charAt's in one char?

    Quote Originally Posted by maskanio View Post
    I want to put the first two spots of an arrays data into one char
    I don't understand this. It almost seems that you're trying to wedge two char into one char, and that obviously can't be done. Again, please tell me what problem this part of your program is trying to solve, rather than how you're trying to solve it with code.

  6. #6
    maskanio is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: How do i put multiple charAt's in one char?

    Ah yeah I guess thats not possible with a char but anyways

    I read a morse code from a text and I need the user to input a number or letter, and the program needs to spit the morse code equivalent back out at the user. I already stored the data from the morse txt into an array. THe problem is the morse .txt is listed with a number or letter in front of it. SO S in the morse txt looks like:
    'S ---'
    When the user asks for S I need the program to return --- and not S ---. I'm so close to getting it finished I need to figure out how to take off the first 2 parts of the data in each array slot whenever they ask for it you know?

  7. #7
    maskanio is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: How do i put multiple charAt's in one char?

    How can I add charAt's? How do I concatenate them

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do i put multiple charAt's in one char?

    It sounds like what you want to use is a Map, perhaps a HashMap<Character, String> so you can associate the char 's' with the String "---". If you have this and load it with all the char and dot-dash Strings that represent Morse code, then you can get the Morse String that corresponds with the 's' character by doing

    String morseString = myMap.get('s');

  9. #9
    maskanio is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: How do i put multiple charAt's in one char?

    That sounds confusing I never used maps

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do i put multiple charAt's in one char?

    They're not that hard once you get used to using them. Say for instance you created a map to translate Spanish words to English:

    Java Code:
    HashMap<String, String> spanishToEnglishMap = new HashMap<String, String>();
    You could fill it like so:

    Java Code:
    spanishToEnglishMap.put("hola", "hello");
    spanishToEnglishMap.put("adiós", "goodbye");
    spanishToEnglishMap.put("muchacho", "boy");
    spanishToEnglishMap.put("muchacha", "girl");
    spanishToEnglishMap.put("mujer", "woman");
    spanishToEnglishMap.put("hombre", "man");
    and then use it like so:

    Java Code:
    String text = "The English word for mujer is " + spanishToEnglishMap.get("mujer");
    System.out.println(text);

  11. #11
    maskanio is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: How do i put multiple charAt's in one char?

    Do I have to declare hashmap as a string or something?

  12. #12
    maskanio is offline Member
    Join Date
    Nov 2012
    Posts
    12
    Rep Power
    0

    Default Re: How do i put multiple charAt's in one char?

    Ah it worked man ty!

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Str.charAt() ?!
    By HearT.Hunt3r in forum New To Java
    Replies: 21
    Last Post: 08-23-2011, 08:42 AM
  2. check a string char by char
    By Sotsiak in forum New To Java
    Replies: 2
    Last Post: 10-23-2010, 10:24 PM
  3. replaceALL(char oldChar, char newChar) method
    By arson09 in forum New To Java
    Replies: 0
    Last Post: 04-28-2010, 06:48 AM
  4. Help with charAt()
    By HackerOfDoom in forum New To Java
    Replies: 7
    Last Post: 03-21-2010, 06:27 PM
  5. drawing char by char with Graphics
    By diggitydoggz in forum New To Java
    Replies: 5
    Last Post: 12-27-2008, 01:49 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
  •