Set an arrays items to new strings
-
Humm this is a puzzler im settings from a .txt file which looks like this //This is the directory which your downloaded files will be stored in DownloadFolder = /mnt/md1/public/Downloads //The telnet user usualy root TelnetUser = root //The telnet password TelnetPassword = root //The IP of your NAS eg 192.168.2.2 TelnetIP = 192.168.2.2 I want to convert these values into strings eg TelnetIP = 192.168.2.2 so they can be reused on multiple forms . So ive got them importing with a StreamReader below private void LoadSettings() { StreamReader Settings = new StreamReader("Settings.txt"); string line; while ((line = Settings.ReadLine()) != null) { if (line.StartsWith("/")) { } else { string[] splitArray = line.Split(new char[] { '=' }); MessageBox.Show(splitArray[0]); } } } So in this case splitArray[0] gives DownloadFolder and splitArray[1] gives /mnt/md1/public/Downloads perfect but how do i join them back togeather to give DownloadFolder = /mnt/md1/public/Downloads And also im getteng blank lines coming through as settings else if (line.StartsWith("/r/n")) or \r\n dosnt seem to catch them any ideas ? thanks
-
Humm this is a puzzler im settings from a .txt file which looks like this //This is the directory which your downloaded files will be stored in DownloadFolder = /mnt/md1/public/Downloads //The telnet user usualy root TelnetUser = root //The telnet password TelnetPassword = root //The IP of your NAS eg 192.168.2.2 TelnetIP = 192.168.2.2 I want to convert these values into strings eg TelnetIP = 192.168.2.2 so they can be reused on multiple forms . So ive got them importing with a StreamReader below private void LoadSettings() { StreamReader Settings = new StreamReader("Settings.txt"); string line; while ((line = Settings.ReadLine()) != null) { if (line.StartsWith("/")) { } else { string[] splitArray = line.Split(new char[] { '=' }); MessageBox.Show(splitArray[0]); } } } So in this case splitArray[0] gives DownloadFolder and splitArray[1] gives /mnt/md1/public/Downloads perfect but how do i join them back togeather to give DownloadFolder = /mnt/md1/public/Downloads And also im getteng blank lines coming through as settings else if (line.StartsWith("/r/n")) or \r\n dosnt seem to catch them any ideas ? thanks
I do not know if this will work but I know when I use string you have to be careful of slashes and so on so for one you could try: private void LoadSettings() { StreamReader Settings = new StreamReader("Settings.txt"); string line; while ((line = Settings.ReadLine()) != null) { if (line.StartsWith(@"/")) { } else { string[] splitArray = line.Split(new char[] { '=' }); MessageBox.Show(splitArray[0]); } } } The at symbol will ensure it is read as string.... as for getting the strings back together you could use a string builder or just add the values together string var = (splitArray[0] + " = " + splitArray[1]); I am not sure if that is the best way to do it. Hope that helps.
-
I do not know if this will work but I know when I use string you have to be careful of slashes and so on so for one you could try: private void LoadSettings() { StreamReader Settings = new StreamReader("Settings.txt"); string line; while ((line = Settings.ReadLine()) != null) { if (line.StartsWith(@"/")) { } else { string[] splitArray = line.Split(new char[] { '=' }); MessageBox.Show(splitArray[0]); } } } The at symbol will ensure it is read as string.... as for getting the strings back together you could use a string builder or just add the values together string var = (splitArray[0] + " = " + splitArray[1]); I am not sure if that is the best way to do it. Hope that helps.