Dropbox Interview Question
Backend DevelopersCountry: United States
1)
private void ReadTxtFile()
{
string filePath = string.Empty;
filePath = openFileDialog1.FileName;
if (string.IsNullOrEmpty(filePath))
{
using (StreamReader sr = new StreamReader(filePath))
{
String line;
while ((line = sr.ReadLine()) != null)
{
FormatData(line);
}
}
}
}
void FormatData(string line)
{
if (line.contains('aaaaab\naaaaa'))
{
globalBool=true;
}
}
2. By checking the character before and after the \n, which needs to be b before and a after if not "b\na" then it is a new line
3. Using stringreader will solve this
To check whether 'aaaaab\naaaaa' is exists in given , need to compare file with 'aaaaab\\naaaaa' beacuse while reading the file \n will be treated as\\n so need to change search string in that way.
- Srinivas March 10, 2017if the file is too big to put into memory you can use File.Readsline() which will read line by line from the given file(c#)
foreach (string line in File.ReadLines(@"Filepath"))