In the program that I create, I created a line in the settings called "Tickers". The scope is the application, and the value is "AAPL, PEP, GILD" without quotes.
I have a RichTextBox called InputTickers where the user must enter stock tickers such as AAPL, SPLS, etc. You understand. When they click the button below InputTickers, I need this to get Settings.Default ["Tickers"]. Then I need to check if any of the tickers that they entered are already in the Tickers list. If not, I need them to add.
After adding them, I need to return it back to the Tickers line in order to save it again in the settings.
I'm still learning coding, so this is my best guess as far as I got this. I can’t figure out how to do it right.
private void ScanSubmit_Click(object sender, EventArgs e) { // Declare and initialize variables List<string> tickerList = new List<string>(); try { // Get the string from the Settings string tickersProperty = Settings.Default["Tickers"].ToString(); // Split the string and load it into a list of strings tickerList.AddRange(tickersProperty.Split(',')); // Loop through the list and do something to each ticker foreach (string ticker in tickerList) { if (ticker !== InputTickers.Text) { tickerList.Add(InputTickers.Text); } } } catch (Exception ex) { MessageBox.Show(ex.Message); }
source share