public List <Message> RedactedWordFilter(List <Message> message, string TargetWord) { try { foreach (var line in message) { if (line.content.Contains(TargetWord)) { FilteredMessages.Add(new Message(line.timestamp, line.senderId, line.content.Replace(TargetWord, redactedWord))); } } return(FilteredMessages); } catch (FormatException) { throw new Exception("Input string is in incorrect format"); } }
public List <Message> KeywordFilter(List <Message> message, string Keyword) { try { foreach (var line in message) { if (line.content.ToLower().Contains(Keyword.ToLower())) { FilteredMessages.Add(new Message(line.timestamp, line.senderId, line.content)); } } return(FilteredMessages); } catch (FormatException) { throw new Exception("Input string is in incorrect format"); } }
private void updateFilter() { if (_filterDuringDay) { ObservableCollection <StateChanged> newColl = new ObservableCollection <StateChanged>(); DateTime currDate = DateTime.MinValue; bool first = true; foreach (var sc in _data.Messages) { if (sc.Time.Date != currDate.Date) { newColl.Add(sc); currDate = sc.Time.Date; first = true; } else if (sc.Time.Date == currDate.Date && first) { newColl.Add(sc); first = false; } else { newColl.RemoveAt(newColl.Count - 1); newColl.Add(sc); } } FilteredMessages.Clear(); foreach (var sc in newColl) { FilteredMessages.Add(sc); } } else { FilteredMessages.Clear(); foreach (var sc in Messages) { FilteredMessages.Add(sc); } } }