using static System.Console;
using System.Collections.Generic;
public static void Main() {
var exemplo = "13032015joao";
var partes = SplitFixed(exemplo, new List<int>() {2, 2, 4, 0});
foreach(var parte in partes) {
var partes2 = SplitFixedTyped(exemplo, new List<Tuple<int, Type>>() {
new Tuple<int, Type>(2, typeof(int)),
new Tuple<int, Type>(2, typeof(int)),
new Tuple<int, Type>(4, typeof(int)),
new Tuple<int, Type>(0, typeof(string))});
foreach(var parte in partes2) {
WriteLine("Dado: {0} - Tipo {1}", parte, parte.GetType());
public static List<String> SplitFixed(string texto, List<int> tamanhos) {
var partes = new List<String>();
foreach(var tamanho in tamanhos) {
partes.Add(texto.Substring(posicao, tamanho));
partes.Add(texto.Substring(posicao));
public static List<object> SplitFixedTyped(string texto, List<Tuple<int, Type>> tamanhos) {
var partes = new List<object>();
foreach(var tamanho in tamanhos) {
partes.Add(Convert.ChangeType(texto.Substring(posicao, tamanho.Item1), tamanho.Item2));
partes.Add(texto.Substring(posicao));
posicao += tamanho.Item1;