write values in a .txt file in C# [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I m new to programming and i m looking for source code which can write and add values to a text file using C# programming. The code should ask the user to input values in the console window. the values are :-
Enter Name, Enter account no., Enter Balance
the output should get stored in the text file in the following format :-
Mark,10001,230000
Steve,10002,32987
Bruce,10003,23454
William,10004,23454
I would appreciate some help.

string name;
int number1,number2;
// Read name, number1, number2 from Console
//.....
//.....
//Saving in a file:
string outputFileName = #"c:\myfile.txt"
StreamWriter sw = new StreamWriter(outputFileName);
sw.WriteLine(string.Format("{0},{1},{2}",name,number1,number2));
sw.Close();

Related

Append multiple text files into single file and Rename the file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hello I have multiple text files in one location and they have names as shown below:-
A_L_PRTD_021345.txt , A_L_PRTD_432124 and so on...
I want to append the contents into single file and want to rename the single file as L_PRTD_Currentdate>.txt
How is it possible?
Can you please show some code for it?
First read each file using File.ReadAllLines(fileName) ;
Then create a single file and append the contents of other files in it
string[] contents1 = File.ReadAllLines(fileName1) ;
string[] contents2 = File.ReadAllLines(fileName2) ;
File.Create(newFileNameHere) ;
File.WriteAllLines(newFileNameHere, contents1) ;
File.AppendAllLines(newFileNameHere, contents2) ;
and so on ...
Check the following documentation of the functions, if you need help:-
http://msdn.microsoft.com/en-us/library/92e05ft3(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/dd383691(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/s2tte0y1(v=vs.110).aspx

How to know the page break in Excel using C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I´m using C# to create and format a Excel spreadsheet, so I need to format (merge cells, change the font, etc) until the final of the first page. How can I know the final line of the page in the Excel spreadsheet?
The following code will give you the last row number before every horizontal page break in an Excel worksheet:
foreach (Excel.HPageBreak pageBreak in worksheet.HPageBreaks)
{
int row = pageBreak.Location.Row - 1;
// ...
}

How to display a string variable in a specific number format like "#,0.##" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a typed dataset with a column called price, which is of string datatype. And I'm showing this via ultrgrid/datagrid
How can I show the price in number format.
For example: price ==123456
in the grid it should be like 12,354,56
Try this
var a = price.ToString("##,###,##");
Reference
Custom Numeric Format Strings!
Look at some of the related links to the right of the screen. Some of them even ask the same question as you !

Line Number of String [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
StreamReader reader = new StreamReader("C:\\ABC\\XYZ.txt");
I am reading a file using streamreader, the file is a HL7 file
MSH|^~\&|ABC|000|ABC|ABC|0000||ABC|000|A|00
PID|1|000|||ABC||000|A||||||||||
PV1|1|O||||||||||||||||||||||||||||||||||||||||||
OBR|1|||00||00|00|||||||||||ABC|00|0|0||||A|||||00||ABC|7ABC||ABC
OBX|1|ABC|ABC|1|SGVsbG8=
I need to find the line number of OBX, the file has character delimiters at the end of each line e.g. MSH|^~\&|ABC|000|ABC|ABC|0000||ABC|000|A|00*CR*LF
The reason I need this is that I need to get the Base64 inside the OBX field, and write it out as a file. my reader will always be a stream, I cannot use the file stream. The above code was an example, the following implementation is to be made in BizTalk and the file I will reading will be stream because that's how BizTalk allows me to access the information in of my file.
var lineNum = File.ReadLines(fname)
.Select((s, line) => new { s, line })
.First(x => x.s.StartsWith("OBX|"))
.line;

How to connect my c# programme to a text file and edit parameters [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I created an application which has 2 labels and 1 textbox.
The first label will show the total number of days since the year began, while the second shows the number of tests in the year. In the textbox shows the number of tests that I have not studied.
When the program opens, you have to click a button to load an .txt file to get these numbers, they are saved when you exit by clicking in another button. I Wanted to know how to load the file and to save the parameters.
I'm developing in C#, grateful, sorry for bad english.
To read text use File.ReadAllLines
List<string> lines = File.ReadAllLines(path).ToList();
To write text use File.WriteAllLines
File.WriteAllLines(path, lines.ToArray());
Or some variation on those methods to suit your needs.
One approach would be this:
using System.IO;
using (var reader = new StreamReader(fileName))
{
string line;
while ((line = reader.ReadLine()) != null)
{
// Do stuff with your line here, it will be called for each
// line of text in your file.
}
}
Or, you could do:
List<String> txtStrings = File.ReadAllLines(path).ToList();
Or, come up with your own approach by reading up on this post.

Categories