using System;
using System.IO;
public class oasis
{
//Convert Biophysical Society Meeting agenda from Oasis format to plain text
//V.V. 02/28/2011. vvostri@gmail.com
public static void Main()
{
string filename;
do
{
Console.WriteLine("Enter itinerary file name");
filename = Console.ReadLine();
if (File.Exists(filename))
{
string[,] data = new string[1, 5];
int counter = 0;
int section_element = 0;
bool section = false;
StreamReader streamvariable = File.OpenText(filename);
string lineinfile;
string[] splitline;
lineinfile = streamvariable.ReadLine();
//Number of events
while (lineinfile != null)
{
if (lineinfile.Contains("
", "<" }, StringSplitOptions.None);
if (splitline.Length == 11)
{
data[counter - 1, 0] = splitline[4];
data[counter - 1, 1] = splitline[8].Trim();
}
}
if (section_element == 2)
{
}
if (section_element == 3 && lineinfile.Contains("B"))
{
splitline = lineinfile.Split(new string[] { "| ", " | ", " " }, StringSplitOptions.RemoveEmptyEntries);
data[counter - 1, 4] = splitline[0];
}
if (section_element == 4)
{
string[] periodsplit = lineinfile.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
string affiliation = null;
string authors = null;
if (periodsplit.Length > 2)
{
//String, containing everything after the last period mark
affiliation = periodsplit[periodsplit.Length - 2] + "." + periodsplit[periodsplit.Length - 1];
//String, containing author list and special characters
affiliation = lineinfile.Substring(0, lineinfile.Length - affiliation.Length);
//Stripping of html tags and separating by author
string[] temp = affiliation.Split(new string[] { ",", "", "", "", "", "" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i != temp.Length; i++)
{
temp[i] = temp[i].Trim();
string[] spacesplit = temp[i].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
if (spacesplit.Length > 1)
{
if (authors == null)
{
authors = temp[i];
}
else
{
authors = authors + ", " + temp[i];
}
}
}
}
data[counter - 1, 2] = authors;
}
if (section_element == 5)
{
//Title
splitline = lineinfile.Split(new string[] { " | ", " ", "", "", "" }, StringSplitOptions.None);
int italics_length = remove_italics.Length;
temp = firstletter + remove_italics[0].Remove(0, 1);
for (int i = 1; i != italics_length; i++)
{
temp += remove_italics[i];
}
data[counter - 1, 3] = temp;
}
section_element++;
}
lineinfile = streamvariable.ReadLine();
}
streamvariable.Close();
//Write the plain text file
FileStream file = new FileStream("BPS_agenda.txt", FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
{
for (counter = 0; counter < N_elements; counter++)
{
sw.Write(data[counter, 0]);
sw.Write(", ");
sw.Write(data[counter, 1]);
if (data[counter, 4] != null)
{
sw.Write(", ");
sw.Write(data[counter, 4]);
}
sw.Write("\r\n");
sw.Write(data[counter, 3]);
sw.Write("\r\n");
sw.Write(data[counter, 2]);
sw.Write("\r\n\r\n");
}
}
sw.Close();
file.Close();
}
else
{
Console.WriteLine("File {0} not found\n", filename);
}
} while (filename != "quit");
}
}
|