在每个位置C#分割字符串

-2 .net c#

So I'm writing a program for a barcodescanner in C# .NET 3.5. When I scan the barcode I get an string with just numbers and I want that string to split at every number and put each number into an int array, but I can´t figure out how. Does someone of you know how to do that?

Mic*_*zyn 7

Try this:

int[] array = "1234567890".ToCharArray().Select(c => int.Parse(c.ToString())).ToArray();
Run Code Online (Sandbox Code Playgroud)

You can omit method invocation of ToCharArray as string is already collection of chars :)

  • 这里不需要`ToCharArray`-`string`已经实现了`IEnumerable <char>` (9认同)