Click here to Skip to main content
16,011,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to replace a dotted lines in a string with space in a notepad without opening it by using a one line code. Are there any possibilities?
Is it possible by lambda expression or any other method?

like example:

File.WriteAllLines(outputpath,File.ReadAllLines(inputpath))
Posted

For ANY operation on the content of the file you MUST first open the file (ReadAllLines does open the file before reading it and closes after)!
However this may help you...
C#
File.WriteAllLines(outputpath,File.ReadAllLines(inputpath).Select(s => s.Replace(".", " ")).ToArray());
 
Share this answer
 
You did not explain what is "dotted line" and what you you mean by "notepad". Notepad is the Microsoft editor application, quite rudimentary one; you can write similar thing yourself. It has nothing to do with your problem. Yes, if the file is not too big, you can use the class System.IO.File to read/write all lines.

Also, the problem is totally unrelated to lambda expressions (after all, just read about them, to learn what they are).

For replacement, you can use:
http://msdn.microsoft.com/en-us/library/system.string.replace%28v=vs.110%29.aspx[^],
or, for more complex cases, http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex%28v=vs.110%29.aspx[^], http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.replace%28v=vs.110%29.aspx[^].

Good luck,
—SA
 
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