-4

There is a file includes some strings, i'm gonna code a C# form project. I need to split them in their ":" and after splitting labels will show that splitted strings.

Here is the text i supposed to split

1096:001:161208:092218:1935:001:H:101:0006:                :00+00000+000000001
1096:001:161208:092218:1935:002:w:100:0006:                :00:00000:00000000R
1096:001:161208:092218:1935:003:S:101:0508:   2416100000006+00010010*000000140
1096:001:161208:092221:1935:004:S:101:0501:   8691397181056+00010010*000000250
1096:001:161208:092228:1935:005:l:100:0000:LCS SUCCESS     :00000000+000000000
1096:001:161208:092231:1935:006:T:110:0006:                :01+00001+000002000
1096:001:161208:092231:1935:007:T:114:0006:                :01+00000-000001610
1096:001:161208:092231:1935:008:V:111:0006:          %1    :00+00001+000000248
1096:001:161208:092231:1935:009:V:110:0006:          %1    :00+00001+000000002
1096:001:161208:092231:1935:010:V:121:0006:          %8    :00+00001+000000130
1096:001:161208:092231:1935:011:V:120:0006:          %8    :00+00001+000000010
1096:001:161208:092231:1935:012:w:100:0006:                :00:00000:00000000R
1096:001:161208:092231:1935:013:q:100:0000:                :000000000000000000
1096:001:161208:092231:1935:014:F:100:0006:                :00+00002+000000390
FIS :001:161208:092231:1935:015: :100:0006:TN 13091080     :00+01178+000000390

The software will import these data from a txt file, after that it will split all ":" and it will write to the labels in form.

It should be like this:

Label1=1096 Label2=001 Label3=161208 Label4=092218 Label5=1935 Label6=001
Label7=H Label8=101 Label9=0006 Label10=00 Label11=00000 Label12=000000001

Also it should sum %1 %1 %8 %8 located spaces between ":" in Label13

Osakawa
  • 3
  • 4
  • 7
    Friendly reminder: Edit your post to insert any code sample you have tried to solve the problem described above (even it doesn't working), otherwise it's out-of-topic without any clue provided. – Tetsuya Yamamoto Jul 07 '17 at 05:51
  • 2
    Please show what did you tried, what is specific problem you are facing? Now it seems you asking us to do your job ;) – Fabio Jul 07 '17 at 05:52
  • You example output looks more like you want to split by `':'` and `'+'`. Any additional desired split symbols? – grek40 Jul 07 '17 at 06:19
  • 2
    You question is essentially a _set of requirements_. [ask] –  Jul 07 '17 at 06:35

1 Answers1

0

String.Split()

While I have that feeling you didn't even try to google your issue, and have no clue how to code anything (String.Split is pretty straight forward), here's some code to get you started:

            string source = @"
1096:001:161208:092218:1935:001:H:101:0006:                :00+00000+000000001
1096:001:161208:092218:1935:002:w:100:0006:                :00:00000:00000000R
1096:001:161208:092218:1935:003:S:101:0508:   2416100000006+00010010*000000140
1096:001:161208:092221:1935:004:S:101:0501:   8691397181056+00010010*000000250
1096:001:161208:092228:1935:005:l:100:0000:LCS SUCCESS     :00000000+000000000
1096:001:161208:092231:1935:006:T:110:0006:                :01+00001+000002000
1096:001:161208:092231:1935:007:T:114:0006:                :01+00000-000001610
1096:001:161208:092231:1935:008:V:111:0006:          %1    :00+00001+000000248
1096:001:161208:092231:1935:009:V:110:0006:          %1    :00+00001+000000002
1096:001:161208:092231:1935:010:V:121:0006:          %8    :00+00001+000000130
1096:001:161208:092231:1935:011:V:120:0006:          %8    :00+00001+000000010
1096:001:161208:092231:1935:012:w:100:0006:                :00:00000:00000000R
1096:001:161208:092231:1935:013:q:100:0000:                :000000000000000000
1096:001:161208:092231:1935:014:F:100:0006:                :00+00002+000000390
FIS :001:161208:092231:1935:015: :100:0006:TN 13091080     :00+01178+000000390            
            ";
            string[] lines = source.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            foreach(string line in lines) {
                string[] values = line.Split(new char[] {':'}, StringSplitOptions.RemoveEmptyEntries);
                int counter = 1;
                foreach(string value in values) {
                    Console.Write("Label" + counter + ": " + value + "   ");
                    counter++;
                }
                Console.WriteLine("-");
            }

            Console.ReadLine();

Just start a new Console Project and paste this in Main(). The rest is up to you.

r41n
  • 908
  • 7
  • 18