8
2
What is the shortest C# statement that will convert a string representation of a number to an int[]
that contains each digit?
string number = "1234";
number.Array.ConvertAll(line.ToCharArray(), c => Int32.Parse(c.ToString()));
number.ToCharArray().Select(i => Convert.ToInt32(i.ToString())).ToArray();
number.Select(i => Int32.Parse(i.ToString())).ToArray();
number.Select(i => i - '0').ToArray();
Can anyone beat my last approach?
You might want to not specify the language, as this is CodeGolf. – phase – 2015-07-17T06:02:09.937
1@phase you have to be kidding me. the language is in the title and the tag. – JJS – 2015-07-17T06:04:02.217
2
@phase's comment refers to the fact that 99% of the "questions" on this site are actually programming contests. However, the community has decided that language-specific "tips" questions like this one are also on topic.
– Dennis – 2015-07-17T06:10:12.473@Dennis thx for the advice. first post on this site, would normally post on stackoverflow, but that community considers code-golf off topic – JJS – 2015-07-17T06:12:07.850
@Dennis I was just about to search meta for that! I do think this would be a nice golf question, if it hasn't been asked already. – phase – 2015-07-17T06:14:15.080
Substract from unicode: https://ideone.com/Z5S43e :D (http://ru.stackoverflow.com/q/446764/178988)
– Qwertiy – 2015-09-07T10:44:47.927