Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a file on the server path "data.txt". It contains a json string. How do I extract that data to a usable string. How do you convert string[] format to string format?
C#
string[] lines = File.ReadAllLines(Server.MapPath("~/data.txt"));
Posted
Comments
Agent__007 6-Jan-15 23:13pm    
Is there a specific reason not to use File.ReadAllText() method? MSDN Reference: http://msdn.microsoft.com/en-us/library/system.io.file.readalltext(v=vs.110).aspx
PIEBALDconsult 6-Jan-15 23:39pm    
Yeah, that's the answer we gave him.
Agent__007 7-Jan-15 1:58am    
Oh, didn't check that. Not sure why he has reposted though, everything was right there! :facepalm:
PIEBALDconsult 6-Jan-15 23:39pm    
We already answered that for you. Please don't respost.

1 solution

Example No 1

C#
// Use string Join to concatenate the string elements.

string result = string.Join("\n", lines);


Example No 2
C#
// Concatenate all the elements into a StringBuilder.

StringBuilder builder = new StringBuilder();
foreach (string value in lines)
{
    builder.Append(value);
    builder.Append('.');
}
string result = builder.ToString();


Please check following link

http://www.dotnetperls.com/convert-string-array-string[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900