|
-
June 15th, 2010, 03:19 PM
#1
Separating line by blank spaces
Hello,
I have a list of values in the following format:
Code:
A12 BC3 4D 5.678 9.123 45
E67 FG89 12H 34.567 8.912 3
I would like to be able to create objects with the name in the first column (i.e, A12 or E67) and have each object contain indexable/searchable attributes from the second and fourth columns (i.e., A12.BC3 = 5.678 & E67.FG89 = 34.567). However, I'm not very good at objects.
Right now I have the following code to try to separate the entries:
Code:
using (StreamReader sr = new StreamReader(fs))
{
while ((line = sr.ReadLine()) != null)
{
manip = line.Split(' ');
foreach (string aline in manip)
{
bool hasvalue = CheckForEntry(aline);
if (hasvalue == true)
{
Console.WriteLine("The next entry is {0}", aline);
Console.ReadLine();
counter++;
//resets counter
if (counter == 6)
{
counter = 1;
}
if (counter == 1)
{
residuename = aline;
Residue residuename = new Residue(); //how to do this correctly??
}
}
}
}
}
Code:
public class Residue
public class Atom
{
{
public float Shift {get; set;}
public Shift(float shift)
{
Shift = shift;
}
}
}
One of my problems is that I'm trying to create a new Residue class called whatever "aline" happens to be at the time and the way I'm doing it now is obviously wrong. Another problem is that my compiler says that public Shift (float shift) must have a return type. Could someone please help me out?
Thanks!
Last edited by Danja91; June 15th, 2010 at 04:16 PM.
-
June 17th, 2010, 07:18 AM
#2
Re: Separating line by blank spaces
This may help you out....
Code:
using (StreamReader sr = new StreamReader(fs))
{
while ((line = sr.ReadLine()) != null)
{
manip = line.Split(' ');
string column1 = manip[0];
string column2 = manip[1];
string column3 = manip[2];
string column4 = manip[3];
string column5 = manip[4];
string column6 = manip[5];
// do the conversions for the numeric values
// then create an object of your custom class using these variables
}
}
The reason for the "public Shift(float shift) must have a return type" is because without a return type, the compiler thinks it's a constructor. A constructor will have the same name as the class. Since you class name is "Atom" and the method name is "Shift", the compiler knows it's not a constructor. So since it's not a constructor, it has to have a return type("void" if nothing is being returned).
===============================
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|