Web Hosting Talk







View Full Version : Problem with an Array in C# -- Split()


FW-Mike
05-23-2005, 11:43 AM
Let me preface this by saying that I am a C# newbie.

I am trying to parse a config file to display the values in input boxes using some sort of a loop for effeciency.



while ((line = sr.ReadLine()) != null)
{
cfg = line.Split('=', '2');
switch (cfg[0])
{
case "path":
this.cfgPath = cfg[1];
break;



And so on. It compiles error free, but the input boxes display nothing. If I change the code to


while ((line = sr.ReadLine()) != null)
{
cfg = line.Split('=', '2');
switch (cfg[0])
{
case "path":
this.cfgPath = cfg[0];
break;



It will display the key that I am trying to sort by -- but I want the value:

The config file lays out like this:


path=
J:\QB\Komp's.QBW
user=
1
passwd=
2


Whats the deal here? How do I get that value.


Also, as a side note, how do I select the actual name of a radio button rather than the name of its group (which is what this.Name does)

unlucky1
05-23-2005, 06:10 PM
try setting your config file like this
path=J:\QB\Komp's.QBW
user=1
passwd=2

error404
05-23-2005, 09:43 PM
If you read in one line at a time with readLine, but your config values are split into two lines, how do you expect the code to parse it properly?

The first iteration through the loop, you're going to have 'path=' in the variable line. When Split() is called on it, you'll end up with ['path', ''] since that's the only element in that string. And so on.

Follow unlucky1's advice.

FW-Mike
05-24-2005, 10:40 AM
Ah! Thanks guys. That did 'er :)