I have this:
String s = "abcd,efgh,ijkl";
I want to convert it into this programmatically:
String[,] s = {{"ab","cd"},{"ef","gh"},{"ij","kl"}};
The string can be of variable length. Can anyone tell me how do I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Splitting into
String[][]can be done like this:Converting to
String[,]requires an additional loop:The 2D part requires that all strings separated by
,be of the same length. Theresarray of arrays, on the other hand, can be “jagged”, i.e. rows could have different lengths.