scott oliver

scott oliver

  • NA
  • 82
  • 14.8k

How to pull the number of items in a string array

Oct 13 2020 1:14 PM
Hello all first off I want to thank everyone who has assisted me on this project. I am now at a point I am trying to get how many items are in this string[]. 
 
Another user on this board helped me with the following code. It uses restsharp to download a csv file and it puts the values in an array to insert into a sqlite db. There is about 12,000 items, and at the end of the file I get an error about an out of bounds value. Its because its blank. What I think I need to do is get the number of items then break the foreach loop. If there is 12500 items I probably need to break on the 12499 item. I also want to add a progress bar. Here is the code the other user assisted with. 
 
In the Locals Watch I see there are 12294 items
{string[12294]} 
 
Thank you again for any help. I have not programmed in years, and it seems my memory is not what it used to be.  
  1. //the csv request
  2. IRestResponse response = restSharpClient.Execute(downloadRequest);  
  3.   
  4. //adding the csv to string array   
  5. string[] strSeparators = new string[] { "\r\n" };  
  6. string[] Lines = response.Content.Split(strSeparators, StringSplitOptions.None);  
  7.    
  8.   //start sqlite insert
  9. foreach (var line in Lines.Skip(1))  
 

Answers (3)