# [SOLVED]How to turn this Pseudo-code into something working?

Status
Not open for further replies.

#### RobertL

##### Newbie level 5
I was looking for a program that is able to split up txt-files at given lines (e.g. lines that start with WORD or lines that have less than say 11 characters). The only programs I could find where programs that could split txt files by filesize, so I wrote 'my program' in pseudocode. The only problem is: I don't know how to get it working. I would like to have it run directly by opening the file, so something like a Batch-file or Java would be OK (those languages I understand a little). Can someone help me translating it? The coding is allready done. Off course, if you know an existing free program that has the same function, that's OK too.

Code:
%% variables:
NUMBER=1    % line number
XX=0        % new files get this number, e.g. file1.txt

while(NUMBER < length(source.txt))
if(length(line(NUMBER)) < 11)
check=1
else
if(check=1)    % the previous line was short and the current line is not
XX++
check=0
(eventually there has to be created a new file sourceXX.txt with instead of XX a number. The name before XX (source in this case) has to stay the same as the original file (in this case 'source.txt'))
end
add a new line to sourceXX.txt (new line without overwriting others. XX is again a number)
end
NUMBER++    % go to next line
end

P.S.: My OS is Windows. source.txt can be in the same directory as this script.

Last edited:

#### bassa

##### Super Moderator
Staff member
Refere this sample code

#### RobertL

##### Newbie level 5
Something like that, but the output should be in seperate new files.
Besides, is it hard to run C# code? How to ignite it?

Staff member

#### bassa

##### Super Moderator
Staff member
check this routine it will create 20 new files for your sample file

Code C# - [expand]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
bool isNewFile =true;
bool isFileClosed = true;

int fileNum = 0;
string outputFileName = String.Concat("C:\\output", fileNum, ".txt");
StreamWriter SW = null;// new StreamWriter(outputFileName);

string w;
string line = "";

{
while ((line = sr.ReadLine()) != null)
{
w = line.Substring(0,10);// (sentence, @"\W");

if (w != "CHECKPOINT")
{
if (isNewFile)
{
outputFileName = String.Concat("C:\\output", fileNum, ".txt");
fileNum++;
SW = new StreamWriter(outputFileName);
isNewFile = false;
isFileClosed = false;
}
SW.WriteLine(line);
}
else
{
isNewFile = true;
if (!isFileClosed)
{
SW.Close();
isFileClosed = true;
}
}
}
}
}
}
}

RobertL

### RobertL

Points: 2

#### RobertL

##### Newbie level 5
Thank you, I will try it tomorrow and let you know.

#### bassa

##### Super Moderator
Staff member
Here you may find the VS2005 (C# 2005) project files

#### Attachments

• ConsoleApplication1.zip
17 KB · Views: 24
RobertL

Points: 2