|
Try this:
string[] lines = File.ReadAllLines(path);
foreach (string s in lines)
{
string[] fragments = s.Split(',');
...
}
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Hi OG,
Thanks alot,
you code works quiet ok but I have another issue, look at my code below:
HttpPostedFile myFile = files.PostedFile;
string strFilename = Path.GetFileName(myFile.FileName);
string[] lines = File.ReadAllLines(strFilename);
foreach (string s in lines)
{
string[] fragments = s.Split(',');
errors.Text = fragments[0];
errors.Visible = true;
}
remember the contents of my file look like:
Kiss,Simwaba,morgan@domain.co.za,0743720187,1987/12/31
Person,Simwaba,morgan@domain.co.za,0743720187,1987/12/31
what happens is that when i pick
errors.Text = fragments[0]; it
returns "Person" which is the first index[0] in the second line.
I don't quiet know why it ignores the first line....
Please help me in case am making a mistake somewhere.
Morg
|
|
|
|
|
Hi,
I am working .net 3.5 version.
I am developing windows application.
I need to add reference the mscorlib dll from the microsoft reference ,
but i cannot able to do that instead of i got this error as follows,
"A reference to 'mscorlib' could not be added' this component is automatically added by the project system and cannot be referenced directly".
So how to resolve this problem..
Can u please explain me...
Thanks & regards,
kannak......
kannak
|
|
|
|
|
sekannak wrote: I need to add reference the mscorlib dll
why is that??
I never felt a need to add it, as it is always present. It is the core of .NET (you could check with Reflector).
|
|
|
|
|
sekannak wrote: instead of i got this error as follows,
"A reference to 'mscorlib' could not be added' this component is automatically added by the project system and cannot be referenced directly".
Just like the error says, it's self explanatory.
Besides, why do you want to reference it? tell me exactly what you want
to do with thi dll,
Morg
|
|
|
|
|
Well huh? If it is not present, that means you explicitly checked that one checkbox in the advanced build settings that says "Do not reference mscorlib.dll" - just uncheck that
|
|
|
|
|
|
That function is not provided by .NET.
But even if it were, mscorlib.dll is referenced already unless you checked said checkbox.
(and btw, it's not like I'd give you any help after you were so nice as to give me a 1-vote)
|
|
|
|
|
Ok I've had it - 2 downvotes without explanation on a completely legitimate post?
No more help from me for at least a year.
|
|
|
|
|
Hi,
I need to use password Encryption file, the file is below
unix_md5_crypt
Fot that i came to know, to include the the reference , am not sure.
Can u please explain ...
kannak
|
|
|
|
|
You don't need to add a reference to mscorlib. All you do is import the System.Cryptography namespace and the classes will be available to you without having to specify the entire namespace path to it.
DId you also realize that MD5 is considered to be broken by the entire industry? It's easily cracked now.
|
|
|
|
|
|
sekannak wrote: I need to add reference the mscorlib dll
No you don't.
Core.dll, maybe, but not mscorlib dll.
|
|
|
|
|
hi,
i have a datagrid control with some data.nw i want to add a separate column containing spin control(up-down) control.how can i do that?
|
|
|
|
|
You have to create your own DataGridViewColumn implementation. It's a lot more work than you'd think to do this. Examples[^]
|
|
|
|
|
Hey,
I'm using that method, but almost always (all executions) i get the same generated random int,
my the min is always 0, and the max moves from 1 to 3 (vector index)
no, almost always i get 0, even if max is 3 (5 executions and it's always 0) the same thing happens when max is 2...
the initialization of random object is with default constructor
new Random();
any idea how to make it be more statistical ?
thanks
p.s
I know that
default constructor works with Clock ticks
(from MSDN)
by default, the parameterless constructor of the Random class uses the system clock to generate its seed value
|
|
|
|
|
you are aware of this:
maxValue
The exclusive upper bound of the random number returned.
?
if so, show actual code and values.
|
|
|
|
|
for (int i = 0; i < zeroFrequencyLetterList.Count && decrypted < 25; i++)
{
bool flag = true;
Random r = new Random();
int randomed;
do
{
randomed = r.Next(0, zeroFrequencyLetterList.Count);
if (encryptionKey[zeroFrequencyLetterList[randomed]] != ' ')
flag = false;
else
flag = true;
} while (!flag);
encryptionKey[zeroFrequencyLetterList[i]] = abcLetters[randomed];
abcLetters.RemoveAt(randomed);
zeroFrequencyLetterList.RemoveAt(i);
decrypted++;
}
|
|
|
|
|
OK.
1.
move Random r = new Random(); outside the for loop, I see no reason to have it inside; normally all you need is a single Random as a class member; and you might make it static.
2.
you are looping the do-while until encryptionKey[zeroFrequencyLetterList[0] is a space; so having random=0 is popular, and even more so when it is the only space in the collection.
|
|
|
|
|
as i already said, usually i've 2-3 empty spaces in collection
but i always get the first place ...
and my description is about application execution, i mean that each time i execute the application, and not during the running time
and your first advice has changed nothing
|
|
|
|
|
I tried this using min 0 and max 10. In my case, it seemed to like the number 3 quite a lot and 0 didn't come up much at all. Interestingly, when I reused the same instance of Random rather than creating a new one each time, I seemed to get a better spread of numbers (purely subjective since humans aren't very good at judging how random a sequence truly is).
The plain truth is that Random isn't particularly random. If you need random numbers that are closer to being genuinely random, use one of the cryptographic random number generators. But, they are quite slow to initialise so in that case you should definitely not create a new one each time through the loop.
|
|
|
|
|
None of that matters as long as you keep making new instances of Random -- do not instantiate Random inside the for loop!
|
|
|
|
|
OK, can you provide the declaration and the content (just before entering the for loop) of zeroFrequencyLetterList? If it varies, just a typical case; if complex, a simplified one that still makes you unhappy about Random.Next
|
|
|
|
|
Off topic, so feel free to ignore this, but your loop count looks a bit odd to me. You increment i and test for it being less than zeroFrequencyLetterList.Count. But you remove an entry from the list each time through the loop. So, this loop will drop out before it has processed the entire list. Here is what happens if you have 10 entries in the list:
i Count
=== =====
0 10
1 9
2 8
3 7
4 6
5 5
The loop will stop at this point, so although you have 10 entries in the list you will only process 5 of them.
Not only that, but you will skip entries in the list. First time through, i is 0 so you remove the entry at index 0, so the entry that was at index 1 is now at index 0, and the entry at index 2 is now at 1. Next time through, i is 1 so you now pick up the entry at index 1 which means you have skipped the entry which was previously at index 1 but is now at index 0. (That's a bit confused, but if you think about it you'll see what I mean.)
That may be what you want, but it looks a bit strange to me.
|
|
|
|
|
you absolutely right,
but luckily i had there another condition && decrypted < 25 therefor it stopped the loop just on time
but you right, I fixed it
Random r = new Random();
int leftLetters = zeroFrequencyLetterList.Count;
for (int i = 0; i < leftLetters && decrypted < 25; i++)
{
bool flag = true;
int randomed;
do
{
randomed = r.Next(0, zeroFrequencyLetterList.Count);
if (encryptionKey[zeroFrequencyLetterList[randomed]] != ' ')
flag = false;
else
flag = true;
} while (!flag);
encryptionKey[zeroFrequencyLetterList[0]] = abcLetters[randomed];
abcLetters.RemoveAt(randomed);
zeroFrequencyLetterList.RemoveAt(0);
decrypted++;
}
modified on Friday, April 9, 2010 8:50 AM
|
|
|
|