Lets say I have the following string:
1111000011001101
How can I extract substrings of 4 chars until the end of the string so that I have the following array ?
|1111|0000|1100|1101|
Lets say I have the following string:
1111000011001101
How can I extract substrings of 4 chars until the end of the string so that I have the following array ?
|1111|0000|1100|1101|
 
    
    Because Strings are only char[]'s you can use the String.Substring(int a, int b) method to retrieve the number of characters specified (int b) from a character position in the string (int a).
If you wanted the first four characters of your string you could use
String s = "1111000011001101";
String firstFourChars = s.Substring(0,4);
 
    
    Playing around with LinqPad I get the following:
var s = "1111000011001101";
var substrings = Enumerable
  .Range(0, s.Length / 4)
  .Select(i => s.Substring(i * 4, 4))
  .ToArray();
substrings.Dump();
Output:
String[] (4 items)
1111 
0000 
1100 
1101 
EDIT: Just noticed this is a duplicate of answer -- see link in the comments of OP. See that link as it gives a general solution.
 
    
    