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. create a .csv file using a variable as the name

create a .csv file using a variable as the name

Scheduled Pinned Locked Moved C#
helpquestion
24 Posts 7 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.
  • D DaveX86

    Dave Kreskowiak wrote:

    Someone told you that "1+1=2" and you said "I KNOW!!", then when they asked you "what's 1+1?", you said you didn't know!

    ...depends on whether or not you're working in binary, hex, decimal, octal...you need to be more specific :)

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #21

    Or strings. Or meta information.

    1 Reply Last reply
    0
    • M mocasu

      ...I know how to concatenate strings! the problem is how I then refer to that "variable" when creating the .csv

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #22

      mocasu wrote:

      ...I know how to concatenate strings! the problem is how I then refer to that "variable" when creating the .csv

      So you don't know how to use a variable instead of a literal string. Here's an example: This is some code with a literal string: Console.WriteLine("Hello world!"); You can put the string in a variable and use that variable in place of the literal string: string message; message = "Hello world!"; Console.WriteLine(message); This is very basic in programming, and what you are trying to do is on a much higher level. You should start with the basics before moving on to more complex things.

      --- single minded; short sighted; long gone;

      1 Reply Last reply
      0
      • M mocasu

        ...and what "good" did sarcasm brought to the whole afair!? ... I see your point Dave... " but when it came to giving a string representing a filename, you suddenly forgot how to do string concantenation! " It wasn't that I forgot,I just didn't know that it could be done like that...as you all might have gueesed by now I am new with this. Anyway, thanks to PIEBALconsul and David for the help

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #23

        mocasu wrote:

        It wasn't that I forgot,I just didn't know that it could be done like that...

        That's why I'm saying that you should start with the basics. If you only can use something in a way that you've seen it used before, you have only learned to mimic others, you haven't really learned how it works.

        --- single minded; short sighted; long gone;

        1 Reply Last reply
        0
        • M mocasu

          ...In case it is not clear... int day = date.Day; int month= date.Month; int year= date.Year; string str="hi"; int res="123"; string fileName = day + month + year + "_" + str + "_" + res However, if I do : File.Create("c:\\code\\fileName.txt"), it creates a file with the name "fileName"...rather than the value of fileName ...any ideas?

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

          You need to buy a book on C# and read it. It's pretty basic stuff that anything in quotes, is a verbatim string. Your variable name becomes a variable name only when it's not in quotes. @"c:\code\" + filename + ".txt";

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          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