Like Tree1Likes
  • 1 Post By Salem

how to convert a string into a 2d char array?

This is a discussion on how to convert a string into a 2d char array? within the C Programming forums, part of the General Programming Boards category; Hey guys, a little help here.I have this string that I need to convert into a 2d char array like ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    9

    how to convert a string into a 2d char array?

    Hey guys, a little help here.I have this string that I need to convert into a 2d char array like this:String str= "A,E,B,I,M,Y#N,R,C,A,T,S";I know how to use delimiter and split string and I know how to convert but only from string to char[].I need something like this:Input: String str= "A,E,B,I,M,Y#N,R,C,A,T,S";Output: [A] [E] [B] [I] [M] [Y][N] [R] [C] [A] [T] [S]

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    > I know how to use delimiter and split string and I know how to convert but only from string to char[]
    OK, so start by splitting at the #
    Then split each one by ,
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    9
    yeah, i thought of that a few seconds after i posted this thread. i'm currently trying that idea out.

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    9
    Code:
    import java.*;
    public  class Test{
    
    
            public String[] getCipherText(String str3){
            String[] array3= str3.split("#");
            String[] a1= array3[0].split(",");
            return a1;    
        }
    
    
        public static void main(String[] args){
                
            String str3;
            str3= "A,B,E,I,M,Y#N,R,C,A,T,S";
            //cph.setCipherText();
              
            System.out.print("Message: "+cph.getCipherText(str3));
            System.out.print("\n");
        }
    }

    I'm having an error here saying: Message: [Ljava.lang.String;@6a5bc8c9
    What's the solution for this?


    But when I change the method into void and print the string array, it works:


    Code:
    import java.*;
    public  class Test{
    
    
            public void getCipherText(String str3){
            String[] array3= str3.split("#");
            String[] a1= array3[0].split(",");
            for(int i=0;i<a1.length;i++)
                System.out.print(a1[i]);
        }
    
    
        public static void main(String[] args){
                
            String str3;
            str3= "A,B,E,I,M,Y#N,R,C,A,T,S";
            //cph.setCipherText();
              
            cph.getCipherText(str3);
            System.out.print("\n");
        }
    }

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    Quote Originally Posted by UltimoBrah View Post
    yeah, i thought of that a few seconds after i posted this thread. i'm currently trying that idea out.
    Perhaps you could also think about why posting Java code on a C board might not be the best idea in the world.
    AndiPersti likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    9
    oh yes, the .......... am i doing. sorry, just got ..........ed up.

  7. #7
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    When I needed some assistance for Java, I used this forum.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert string to char or use 2d array of char?
    By simpleblue in forum C++ Programming
    Replies: 6
    Last Post: 09-25-2011, 06:00 PM
  2. Replies: 11
    Last Post: 06-16-2011, 12:59 PM
  3. Replies: 2
    Last Post: 09-12-2010, 10:15 AM
  4. convert char** (c string array) to std::string[]
    By umen242 in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2008, 05:52 AM
  5. convert string to char array
    By Dan17 in forum C++ Programming
    Replies: 6
    Last Post: 03-09-2006, 11:47 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21