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. File

File

Scheduled Pinned Locked Moved C#
question
5 Posts 4 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.
  • R Offline
    R Offline
    Reza Shojaee
    wrote on last edited by
    #1

    Hi everybody How can find out number of characters in a file?

    Best Regards, Reza Shojaee

    C realJSOPR 2 Replies Last reply
    0
    • R Reza Shojaee

      Hi everybody How can find out number of characters in a file?

      Best Regards, Reza Shojaee

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

      File.ReadAllBytes.Count, or something like that You may be able to get it from the FileInfo class also.

      Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

      L 1 Reply Last reply
      0
      • C Christian Graus

        File.ReadAllBytes.Count, or something like that You may be able to get it from the FileInfo class also.

        Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Christian Graus wrote:

        File.ReadAllBytes.Count, or something like that

        That'll work for ASCII and UTF-32, but not for UTF-8 and some other encodings with variable character length. File.ReadAllText(path).Length should work better. regards

        C 1 Reply Last reply
        0
        • L Lost User

          Christian Graus wrote:

          File.ReadAllBytes.Count, or something like that

          That'll work for ASCII and UTF-32, but not for UTF-8 and some other encodings with variable character length. File.ReadAllText(path).Length should work better. regards

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

          Depends, if it's a text file or a binary file, and if he wants file size, or number of characters.

          Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

          1 Reply Last reply
          0
          • R Reza Shojaee

            Hi everybody How can find out number of characters in a file?

            Best Regards, Reza Shojaee

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            using System.IO;

            FileInfo info = new FileInfo("filename.txt");
            long charCount = info.Length;

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            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