How can I use System.IO to do these 3 things [modified]
-
I have not yet manipulated text files so I need some help performing the following tasks: 1. I need to access a letter in a name (eg the 'h' in John) 2. I also need to find the name's position in a list of names (eg Joey is in position 3 here: John, Sally, Joey, Paul) 3. Finally I need to find the length (number of letters) of a name (eg the lenth of Paul is 4) I am not limited to System.IO, but I am assuming that is the namespace that should be used for these tasks, so if one of these tasks require something not is System.IO then please tell me. Edit: The names are in "name1", "name2", "name3" format in the textfile. This might make things easier. Edit 2: Never mind I already got it. The trick is to store the file as a string and use the methods in the IEnumerator class.
modified on Tuesday, August 4, 2009 12:53 AM
-
I have not yet manipulated text files so I need some help performing the following tasks: 1. I need to access a letter in a name (eg the 'h' in John) 2. I also need to find the name's position in a list of names (eg Joey is in position 3 here: John, Sally, Joey, Paul) 3. Finally I need to find the length (number of letters) of a name (eg the lenth of Paul is 4) I am not limited to System.IO, but I am assuming that is the namespace that should be used for these tasks, so if one of these tasks require something not is System.IO then please tell me. Edit: The names are in "name1", "name2", "name3" format in the textfile. This might make things easier. Edit 2: Never mind I already got it. The trick is to store the file as a string and use the methods in the IEnumerator class.
modified on Tuesday, August 4, 2009 12:53 AM
System.IO contains nothing to do these things, why should it ? File.ReadAllText or File.ReadAllLines will read a text file. Then the string class contains everything you need to do this stuff.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
I have not yet manipulated text files so I need some help performing the following tasks: 1. I need to access a letter in a name (eg the 'h' in John) 2. I also need to find the name's position in a list of names (eg Joey is in position 3 here: John, Sally, Joey, Paul) 3. Finally I need to find the length (number of letters) of a name (eg the lenth of Paul is 4) I am not limited to System.IO, but I am assuming that is the namespace that should be used for these tasks, so if one of these tasks require something not is System.IO then please tell me. Edit: The names are in "name1", "name2", "name3" format in the textfile. This might make things easier. Edit 2: Never mind I already got it. The trick is to store the file as a string and use the methods in the IEnumerator class.
modified on Tuesday, August 4, 2009 12:53 AM
if names are like the following code(with quote) then you should learn Regular Expression(The 30 Minute Regex Tutorial[^])
string names = "\"name1\", \"name2\", \"name3\"";
and you can get Index of any string in string through
IndexOf()
, it will return -1 if there is nothing that matches with specified string or char.TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
I have not yet manipulated text files so I need some help performing the following tasks: 1. I need to access a letter in a name (eg the 'h' in John) 2. I also need to find the name's position in a list of names (eg Joey is in position 3 here: John, Sally, Joey, Paul) 3. Finally I need to find the length (number of letters) of a name (eg the lenth of Paul is 4) I am not limited to System.IO, but I am assuming that is the namespace that should be used for these tasks, so if one of these tasks require something not is System.IO then please tell me. Edit: The names are in "name1", "name2", "name3" format in the textfile. This might make things easier. Edit 2: Never mind I already got it. The trick is to store the file as a string and use the methods in the IEnumerator class.
modified on Tuesday, August 4, 2009 12:53 AM
First, use File.ReadAllText to get the file in a string variable and split it on "," to get an array of names. Then you can carry out the other things using methods in string class.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
-
System.IO contains nothing to do these things, why should it ? File.ReadAllText or File.ReadAllLines will read a text file. Then the string class contains everything you need to do this stuff.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Why the hell did you get downvoted for that? :confused: Anyway evened it out a bit ;P