c# - Delete hashs from line but keep string -


i writing program re-writes text file - needed remove line "#" in it, worked fine - need remove hashes keep string between hashes. example "#####texthere##### want texthere string...

here code:

            string linedata = "#";             string copy = "rcpy";              string dash ="-------";             string total = "total";             string vv = "vvcp";              int count = 0;             string name = "name";              // read file , display line line.             using (system.io.streamreader file = new system.io.streamreader(textbox1.text))             {                 using (system.io.streamwriter writer = new system.io.streamwriter(@"c:\test4.txt"))                 {                     //while reader reads lines, perform re-write based on these conditions                     while ((line = file.readline()) != null)                     {                         line = line.trim();                          if (line.contains(name))                         {                             count++;                         }                          if (line.contains(name) && count >= 2 || line.contains(copy) ||               line.contains(dash) || line.contains(total) || line.contains(vv)) || line.contains(linedata))                           {                             //then right new file                         }                          else                         {                             string[] keys = new string[] { "r1", "r5" };                             string result = keys.firstordefault<string>(s=>line.contains(s));                              switch(result)                             {                                 case "r1":                                     writer.writeline("r5" + "\t" + line);                                     break;                                 case "r5":                                     writer.writeline("r1" + "\t" + line);                                     break;                                 default:                                     writer.writeline("\t" + line);                                     break;                             }                             //then right new file                         }                      }                 }                 messagebox.show("formatting complete");             }         }     } 

you can use below menioned code

if(line.contains(linedata)) {  line=line.replace("#",""); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -