♣
c# 读写文件操作,高分求答案,急
我要用c# 写个小东西 ,打开一个文本,然后对文本里面的内容操作,例如 rere(ere)rerer_erere
rere )ere
把 ")" 右边的文字变大写,并且把")" 符号删除,谢谢.
· 网友精彩回答:
http://www.programfan.com/article/showarticle.asp?id=2210
http://www.programfan.com/article/showarticle.asp?id=1992
看下这个咯
是很简单的、使用indexof和toupper就可以出来了
<%@ 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();
}
}
}
}
}
- 更多问题:
- · 送分了,贴了一天没人答
- · 庫函數的問題
- · 条马枪开发包
- · 请教关于MSC1210的问题
- · 关于HIBERNATE查询的错误请大家指点。
- · 化境无组件上传在WINDOWS 2003下不能用?怎么改好?
- · 关于证书导入导出的一个问题(急)
- · 怎么取程序运行所花的时间,比如网络蚂蚁等下载软件,可以计算每个下载的东西已经花费了多少时间。
- · 求Crystal Reports10 的下载地址,谢谢!!
- · 只因脸上伤痕,医学院拒绝录用上线农村女生! (ZT)
- · 一个小问题.
- · 关于dbcombobox的问题
- · ATL类型的ActiveX控件打成cab包,里面可以包含非控件类型的动态库文件吗?
- · 偶找到女朋友了,散200分,开心一下!
- · 机器更换硬盘后启动不起来.
- · 两个关于ADO.NET2的问题

