Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can I use System.IO to do these 3 things [modified]

How can I use System.IO to do these 3 things [modified]

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nathan Revka
    wrote on last edited by
    #1

    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

    C X D 3 Replies Last reply
    0
    • N Nathan Revka

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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.

      T 1 Reply Last reply
      0
      • N Nathan Revka

        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

        X Offline
        X Offline
        Xmen Real
        wrote on last edited by
        #3

        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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

        ----------------------------------------------- 128 bit encrypted signature, crack if you can

        1 Reply Last reply
        0
        • N Nathan Revka

          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

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C Christian Graus

            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.

            T Offline
            T Offline
            Tom Deketelaere
            wrote on last edited by
            #5

            Why the hell did you get downvoted for that? :confused: Anyway evened it out a bit ;P

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups