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. Put values from a text file in a matrix.

Put values from a text file in a matrix.

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 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.
  • X Offline
    X Offline
    xkrja
    wrote on last edited by
    #1

    I have a textfile with values separated by tabs. It looks like below (only difference is that there can be many more columns and rows): Voltage Temperature 6.41000 4.76610 3.41000 4.76366 6.41000 4.83936 6.41000 5.00298 6.41000 5.01763 6.41000 5.05670 Can anyone suggest a method to read from the text file and put the values in a matrix??? The problem is that nothing is known from the beginning. I was thinking of using ReadLine() and then break up the line in smaller pieces (one piece per value) but I find it hard to do because of all the unknown parameters (number of characters in each value, number of columns in the text file etc.) Thanks!

    G 1 Reply Last reply
    0
    • X xkrja

      I have a textfile with values separated by tabs. It looks like below (only difference is that there can be many more columns and rows): Voltage Temperature 6.41000 4.76610 3.41000 4.76366 6.41000 4.83936 6.41000 5.00298 6.41000 5.01763 6.41000 5.05670 Can anyone suggest a method to read from the text file and put the values in a matrix??? The problem is that nothing is known from the beginning. I was thinking of using ReadLine() and then break up the line in smaller pieces (one piece per value) but I find it hard to do because of all the unknown parameters (number of characters in each value, number of columns in the text file etc.) Thanks!

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      If you know the character that will separate columns, you can use ReadLine() method and than use Split() method of string class. There are several libraries at codeproject that can help you in reading csv files.

      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

      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