Reputation: 73
I'm importing a .txt file into a Microsoft Excel sheet, it works great, but the problem is when i want to edit the content of the cells, for example I have my columns and then pass it to the Excel sheet, and this is what I get inside de cell "Patient Name:Robin", I only want to have in that cell the content that is after the ":". Here is my code.
System.IO.StreamReader archivo = new System.IO.StreamReader(NombreFile);
int lineacnt = 0;
string[] ListInfo = new string[49];
for (int b = 1; b < 49; b++)
{
ListInfo[b] = archivo.ReadLine();
//Here I got an error of an object reference//
**contenidoEMG[0, i] = ListInfo[7].Remove(ListInfo[7].IndexOf(':'));**
contenidoEMG[1, i] = ListInfo[11];
contenidoEMG[2, i] = ListInfo[12];
Upvotes: 0
Views: 133
Reputation: 11910
What are you doing to check that ListInfo[7]
is a proper string and not null? That could be where you're having a problem.
Upvotes: 0
Reputation: 670
string.Remove(int startIndex) returns a string with all characters following the startIndex removed.
var str = "patient name:Robin";
var newStr = str.Remove(str.IndexOf(':'));
Console.WriteLine(newStr); // prints 'patient name'
If you want Robin, the you should do str.Remove(0, str.IndexOf(':')+1);
Upvotes: 1