当前位置:首页 > 技术问答集
firefox

c# 读写文件操作,高分求答案,急

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

我要用c#   写个小东西   ,打开一个文本,然后对文本里面的内容操作,例如     rere(ere)rerer_erere      
  rere   )ere    
  把   ")"   右边的文字变大写,并且把")"   符号删除,谢谢.

· 网友精彩回答:

发表者:jimu8130

http://www.programfan.com/article/showarticle.asp?id=2210  
  http://www.programfan.com/article/showarticle.asp?id=1992  
  看下这个咯  
 

发表者:brando_beat

是很简单的、使用indexof和toupper就可以出来了

发表者:daishengs

<%@   page   language="c#"   codebehind="opertxt.aspx.cs"   autoeventwireup="false"   inherits="commonfunction.opertxt"   %>  
  <!doctype   html   public   "-//w3c//dtd   html   4.0   transitional//en"   >  
  <html>  
  <head>  
  <title>opertxt</title>  
  <meta   name="generator"   content="microsoft   visual   studio   7.0">  
  <meta   name="code_language"   content="c#">  
  <meta   name="vs_defaultclientscript"   content="javascript">  
  <meta   name="vs_targetschema"   content="http://schemas.microsoft.com/intellisense/ie5">  
  </head>  
  <body   ms_positioning="gridlayout">  
  <form   id="opertxt"   method="post"   runat="server"   enctype="multipart/form-data">  
  <font   face="宋体">  
  <asp:textbox   id="txtcontent"   style="z-index:   101;   left:   40px;   position:   absolute;   top:   20px"   runat="server"   textmode="multiline"   height="429px"   width="326px"></asp:textbox>  
  <asp:button   id="btnread"   style="z-index:   102;   left:   395px;   position:   absolute;   top:   82px"   runat="server"   width="53px"   text="读取"></asp:button>  
  <asp:button   id="btnrepaire"   style="z-index:   103;   left:   459px;   position:   absolute;   top:   83px"   runat="server"   width="52px"   text="更改"></asp:button>  
  <input   id="filepath"   style="z-index:   105;   left:   396px;   position:   absolute;   top:   46px"   type="file"   name="file1"   runat="server"></font>  
  </form>  
  </body>  
  </html>  
   
   
   
  using   system;  
  using   system.collections;  
  using   system.componentmodel;  
  using   system.data;  
  using   system.drawing;  
  using   system.web;  
  using   system.web.sessionstate;  
  using   system.web.ui;  
  using   system.web.ui.webcontrols;  
  using   system.web.ui.htmlcontrols;  
  using   system.text;  
  using   system.io;  
  namespace   commonfunction  
  {  
  ///   <summary>  
  ///   opertxt   的摘要说明。  
  ///   </summary>  
  public   class   opertxt   :   system.web.ui.page  
  {  
  protected   system.web.ui.webcontrols.textbox   txtcontent;  
  protected   system.web.ui.webcontrols.button   btnread;  
  protected   system.web.ui.htmlcontrols.htmlinputfile   filepath;  
  protected   string   txtfilepath,fileextname;  
  protected   system.web.ui.webcontrols.button   btnrepaire;  
   
  private   void   page_load(object   sender,   system.eventargs   e)  
  {  
  //   在此处放置用户代码以初始化页面  
  }  
   
  #region   web   form   designer   generated   code  
  override   protected   void   oninit(eventargs   e)  
  {  
  //  
  //   codegen:该调用是   asp.net   web   窗体设计器所必需的。  
  //  
  initializecomponent();  
  base.oninit(e);  
  }  
   
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   initializecomponent()  
  {          
  this.btnread.click   +=   new   system.eventhandler(this.btnread_click);  
  this.btnrepaire.click   +=   new   system.eventhandler(this.btnrepaire_click);  
  this.load   +=   new   system.eventhandler(this.page_load);  
   
  }  
  #endregion  
   
  private   void   btnread_click(object   sender,   system.eventargs   e)  
  {  
  if(filepath.postedfile.filename   !=   "")  
  {  
  txtfilepath   =filepath.postedfile.filename;  
  fileextname   =   txtfilepath.substring(txtfilepath.lastindexof(".")+1,3);  
   
  if(fileextname   !="txt"   &&   fileextname   !=   "txt")  
  {  
  response.write("请选择文本文件");  
  }  
  else  
  {  
  streamreader   filestream   =   new   streamreader(txtfilepath,encoding.default);  
  txtcontent.text   =   filestream.readtoend();  
  filestream.close();  
  }  
  }  
  }  
   
  private   void   btnrepaire_click(object   sender,   system.eventargs   e)  
  {  
  if(filepath.postedfile.filename   !=   "")  
  {  
  txtfilepath   =filepath.postedfile.filename;  
  fileextname   =   txtfilepath.substring(txtfilepath.lastindexof(".")+1,3);  
   
  if(fileextname   !="txt"   &&   fileextname   !=   "txt")  
  {  
  response.write("请选择文本文件");  
  }  
  else  
  {  
  streamwriter   filewrite   =   new   streamwriter(txtfilepath,false,encoding.default);  
  filewrite.write(txtcontent.text);  
  filewrite.close();  
   
  }  
  }  
  }  
   
   
  }  
  }  
 

.
© 2006-2008 All Rights Reserved