Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I know how to put string list to a .txt file for example:
//nw_TCList is a string list
string nwFinal = String.Join("\n", nw_TCList.ToArray());
System.IO.File.WriteAllText(nwPath, nwFinal);
So my question is how to put this string list file to a .list file?
-------------Question update
Thank you for all the reply, nwPath is my txt file address. (#"c:\abc\name.txt")
Problem solved! just change .txt to .list, LOL, i was thinking how to convert txt file to list file before, haha.
.list is just Extension so don't worry about that
there is direct method to write Array to file
System.IO.File.WriteAllLines(nwPath, nw_TCList);
And If you want to have .list Extension
give that in path param
E.g.
System.IO.File.WriteAllLines("D://Data.list", nw_TCList);
that did trick for me
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I'm using csharp in console.net
I want to get a txt file from the user as input
But I do not want the text inside the txt file to be displayed to the user
Instead, I want the text to be hidden and the number of lines to be displayed instead
If I understood you fine, you want to count the number of lines in the txt file, right?
A basic approach could be:
string[] fileLines = System.IO.File.ReadAllLines("<path to the file>");
if (fileLines != null)
Console.WriteLine($"The file has {fileLines.Length} lines.");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
What does this code mean? Somehow it generates a .csv file on my side but I cannot seem to find it. I am using it as a data source.
public CSVRepository()
{
var filename = ConfigurationManager.AppSettings["CSVFileName"];
path = AppDomain.CurrentDomain.BaseDirectory + filename;
}
The code runs as the constructor of a class. It looks in an app.config xml file to find a CSVFileName xml element. It uses the value of the element as a filename (no path, just the name). Then it looks up the path where the program is running, appends the filename to that path, and sets the result to a member field in the class that will be used by other code in the class to write out your csv file.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am having file name as below.
i need only sample.xml as result.
sample.xml.jued.783737377365474.da
Please help me on this. thanks in Advance
File name can have one extension only:
string path = "sample.xml.jued.783737377365474.da";
// ".da"
var ext = Path.GetExtension(path);
However, in case you have a origin.extension.[some data].da pattern, you can split the file name by . and take first two items:
// sample.xml
var origin = String.Join(".", Path
.GetFileName(path)
.Split(new char[] { '.' }, 3)
.Take(2));
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have string "my string" taken from excel value, I used GemBox.Spreadsheet library. But the result I have """my string""". How to get back my real string value as "my string
Thanks
Use the hex escape \x22 such as:
Console.WriteLine ("\x22Literally\x22");
Outputs "Litterally"
okay I just go to GemBox Convert I try upload my excel file, then convert into csv file, and the result is same as my convert file. So the problem is not coming from my script but in GemBox.Spreadsheet library. Thank you for your participate guys!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a C# task to do and I am stuck on part of the coding. I am using StreamReader to read a .txt file which contains group exam grade data (e.g. ADCBCBBBADEBCCBADBAACDCCBEDCBACCFEABBCBBBCCEAABCBB), I need the code to work out how many A's, B's etc there are inside each set of data, I thought about using some form of count++ code but each attempt just throws errors.
I want it to print onto console the number of A's in that line of the .txt file.
I hope that makes sense, I understand how to do the rest but I just needed a hand on this section.
Consider using System.Linq, eg...
string myString = "ADCBCBBBADEBCCBADBAACDCCBEDCBACCFEABBCBBBCCEAABCBB";
int countOfAs = myString.Count(x => x == 'A');
//Result: 9