0

What I want is to write a sentence in a text file. The sentence is 'function(a,b,c)' as below and a, b, c are variables.

using (var tw = new StreamWriter(path, false))
        {
            tw.WriteLine("data_reformat.reformat('a','b','c')");
        }

It finally shows in a .txt

data_reformat.reformat('a','b','c')

However what I want is

data_reformat.reformat('A1','Date','ID')

where

a = 'A1'
b = 'Date'
c = 'ID'

So how to write like this and do I need to use other functions?

Andy
  • 101
  • 1
  • 1
  • 7

1 Answers1

0

You are inserting the string and not the variables. You could insert your variables by using string concatenation. A better approach would be to use string.Format like in the example.

tw.WriteLine(string.Format("'{0}','{1}','{2}'"), a, b, c);

When using string.Format you specify the string you want to format. The numbers in the curly braces specify what variable you will insert. You specify the variables as the second, third and fourth argument. Note thay you can insert as many variables qs you want.

gogibogi4
  • 263
  • 4
  • 15