С Regex
:
using (var streamReader = new StreamReader(new IsolatedStorageFileStream("ViewFolder\\myFile.txt", FileMode.Open, myStore)))
{
var text = streamReader.ReadToEnd();
var titles = Regex.Matches(text, @"(?<title>[^\^]+)\^(?<note>[^\^]+)\^(?<imagePath>[^\^]+)")
.Cast<Match>()
.Select(arg => arg.Groups["title"])
.ToList();
}
или с Split
using (var streamReader = new StreamReader(new IsolatedStorageFileStream("ViewFolder\\myFile.txt", FileMode.Open, myStore)))
{
var text = streamReader.ReadToEnd();
var i = 0;
var titles = text.Split('^').Where(arg => i++ % 3 == 0).ToList();
}
[РЕДАКТИРОВАТЬ] Чтобы связать список с ListBox
:
private void Library_Loaded(object sender, RoutedEventArgs e)
{
using (var streamReader = new StreamReader(new IsolatedStorageFileStream("ViewFolder\\myFile.txt", FileMode.Open, myStore)))
{
var text = streamReader.ReadToEnd();
var i = 0;
MainListBox.ItemsSource = text.Split('^').Where(arg => i++ % 3 == 0).ToList();
}
}
[РЕДАКТИРОВАТЬ]
Заменить этот код:
String fileText = readFile.ReadLine();
//noteSeparated is the variable that save the retrieve note from myFile.txt and is noteSeparated by '^'
noteSeparated = fileText.Split(new char[] { '^' });
for (i = 0; i < noteSeparated.Length; i = i + 3)
{
noteSeparate = noteSeparated[i];
a = noteSeparate;
break;
}
h = a;
на:
var fileText = readFile.ReadToEnd();
var i = 0;
var titles = fileText .Split('^').Where(arg => i++ % 3 == 0).ToList();
titles
будет список notTitle
.