c# jq替换html内容替换

代码里用到一个变量,具体类型尚未确定,可能需要UInt32,也可能得用UInt64,我想写:#define DataIDType UInt32结果VS不支持。。。
写public class DataIDType : UInt32{}然后用到的地方又提示无法隐式地将uint型转为DataIDType型。。。
要是为了这个专门写一些构造方法,是不是太麻烦了。
大家怎么解决这种问题的呢
该问题被发起重新开启投票
投票剩余时间:
之前被关闭原因:
该问题被发起删除投票
投票剩余时间:
距离悬赏到期还有:
参与关闭投票者:
关闭原因:
该问题已经被锁定
锁定原因:()
保护原因:避免来自新用户不合宜或无意义的致谢、跟帖答案。
该问题已成功删除,仅对您可见,其他人不能够查看。
如果用预编译命令解决1, 在类的头部写上#define UInt32或者在项目的环境变量定义
2,在用到这个变量的时候
#if UInt32UInt32 typeN#elseUInt64 typeN#end if
自己写类解决,关键在于重写隐式和显式转换
public class DataIDType
public UInt64 Value { }
public DataIDType(UInt32 value)
public DataIDType(UInt64 value)
static public implicit operator DataIDType(UInt32 value)
return new DataIDType(value);
static public implicit operator DataIDType(UInt64 value)
return new DataIDType(value);
static public explicit operator UInt32(DataIDType data)
return (UInt32)data.V
static public explicit operator UInt64(DataIDType data)
return data.V
Using DataIDType=System.UInt32
这样就可以了
考虑使用泛型public class DataIDType&T&{
//实现代码..}public class ABC{
DataIDType&int& dit = new DataIDType&int& ();}
不能这么写的,UInt32,UInt64是结构体,不能被继承。。。如果你真的想接收这样的变量就不用在乎存进去的是什么类型,object 就足够了,例如:
public class DataIDType
public object Data
if (data is UInt32 || data is UInt64)
存入数据时调用Data属性。虽然最后取出的是object,但里面的数据类型只有可能是UInt32或者UInt64。
不是您所需,查看更多相关问题与答案
<a href="http://www.dewen.net.cn/search/q/c# c# <class
德问是一个专业的编程问答社区,请
后再提交答案
关注该问题的人
共被浏览 (18652) 次C#教程之字符串替换Replace仅替换第一个字符串匹
来源:未知
public static string Replace(string source, string match, string replacement)
&&&&&&&&&&& char[] sArr = source.ToCharArray();
&&&&&&&&&&& char[] mArr = match.ToCharArray();
&&&&&&&&&&& char[] rArr = replacement.ToCharArray();
&&&&&&&&&&& int idx = IndexOf(sArr, mArr);
&&&&&&&&&&& if (idx == -1)
&&&&&&&&&&& {
&&&&&&&&&&&&&&&
&&&&&&&&&&& }
&&&&&&&&&&& else
&&&&&&&&&&& {
&&&&&&&&&&&&&&& return new string(sArr.Take(idx).Concat(rArr).Concat(sArr.Skip(idx + mArr.Length)).ToArray());
&&&&&&&&&&& }
&&&&&&& /// &summary&
&&&&&&& /// 查找字符数组在另一个字符数组中匹配的位置
&&&&&&& /// &/summary&
&&&&&&& /// &param name=&source&&源字符数组&/param&
&&&&&&& /// &param name=&match&&匹配字符数组&/param&
&&&&&&& /// &returns&匹配的位置,未找到匹配则返回-1&/returns&
&&&&&&& private static int IndexOf(char[] source, char[] match)
&&&&&&&&&&& int idx = -1;
&&&&&&&&&&& for (int i = 0; i & source.Length - match.L i++)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (source[i] == match[0])
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& bool isMatch =
&&&&&&&&&&&&&&&&&&& for (int j = 0; j & match.L j++)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& if (source[i + j] != match[j])
&&&&&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&&&&&& isMatch =
&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& if (isMatch)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& idx =
&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&&
-----------下次自动登录
现在的位置:
& 综合 & 正文
C#实现WORD文档的内容复制和替换
最近一个项目的需求是要根据一个Word文档的模板,用记录集的具体内容替换掉里面的标识字符的内容,生成不同的文档。
第一:复制模板的内容到一个Document对象里
从源DOC文档复制内容返回一个Document类#region 从源DOC文档复制内容返回一个Document类
/// 从源DOC文档复制内容返回一个Document类
&/summary&
&param name="sorceDocPath"&源DOC文档路径&/param&
&returns&Document&/returns&
protected Document
copyWordDoc(object sorceDocPath)
object objDocType
= WdDocumentType.wdTypeD
object type
= WdBreakType.wdSectionBreakC
//Word应用程序变量
Application
//Word文档变量
object readOnly
object isVisible
//由于使用的是COM库,因此有许多变量需要用Missing.Value代替
= new ApplicationClass();
Nothing = System.Reflection.Missing.V
= wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
newWordDoc
= wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
= wordApp.Documents.Open(ref sorceDocPath, ref Nothing, ref readOnly, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref isVisible, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
openWord.Select();
openWord.Sections[1].Range.Copy();
object start
newRang = newWordDoc.Range(ref start, ref start);
//插入换行符
//newWordDoc.Sections[1].Range.InsertBreak(ref
newWordDoc.Sections[1].Range.PasteAndFormat(WdRecoveryType.wdPasteDefault);
openWord.Close(ref Nothing, ref Nothing, ref Nothing);
return newWordD
#endregion
第二:替换复制好内容的Document的标识字符
替换指定Document的内容,并保存到指定的路径#region 替换指定Document的内容,并保存到指定的路径
/// 替换指定Document的内容,并保存到指定的路径
&/summary&
&param name="docObject"&Document&/param&
&param name="savePath"&保存到指定的路径&/param&
protected void ReplaceWordDocAndSave(Document
docObject, object savePath)
object format
= WdSaveFormat.wdFormatD
object readOnly
object isVisible
string strOldText
= "{WORD}";
string strNewText
= "{替换后的文本}";
List&string&
IListOldStr = new List&string&();
IListOldStr.Add("{WORD1}");
IListOldStr.Add("{WORD2}");
<img align="top" src="http://blog.51cto.com/images/editer/InBlock.gif" alt="" style="padding-top:0 padding-right:0 padding-bottom:0 padding-left:0 margin-top:0 margin-right:0 margin-bottom:0 margin-left:0 vertical-align: border-style: border-color: bor
【上篇】【下篇】1被浏览304分享邀请回答暂时还没有回答,开始写第一个回答文本替换C#版(文本批量替换小工具)V1.0.1 绿色版软件下载 - 绿色先锋下载 - 绿色软件下载站
赞助商链接
本类月下载排行
本类周下载排行
常用软件推荐
文本替换C#版(文本批量替换小工具)是一款功能相当不错的文本内容替换辅助软件。由于Visual Studio2010在查找替换时,如果以整个解决方案为查找范围,则查找替换会崩溃,因此就用Visual Studio20010编写了一个文本批量替换小工具,用编程来完善编程工具,能够支持文本查找、批量查找、替换、批量替换等各种处理,从而让大家更加快速的处理文本内容!
使用说明:
此工具只有一个功能:就是批量替换某文件夹内的所有文本文件,可以一次性查找替换多个关键词。
此工具的编程思路是:识别文件的编码方式,然后一次性读入并查找替换之,最后再按原编码方式写出文件。
此工具可以识别以下4种文本编码格式:Encoding.UTF8、Encoding.BigEndianUnicode、Encoding.Unicode、UTF8Encoding(false)。
注意:此工具只可以查找替换文本文件,比如cs文件、txt文件、m文件&&
&&请点击以下链接下载该软件:&文本替换C#版(文本批量替换小工具)V1.0.1 绿色版
上一软件:
下一软件:
(评论内容只代表网友观点,与本站立场无关)
为了保证您快速的下载,推荐使用[] 、[] 等专业工具下载.
为确保软件能正常使用,请使用[
]解压本站软件.
目前不少软件都捆绑流氓插件,请在安装的之时务必留意每一个安装步骤.绿色先锋本身是不会捆绑任何插件在软件中的.
该软件为网上收集,若无意中侵犯了您的版权,.我们将在收信后24小时内删除侵权内
本站下载的软件中,部分软件经过压缩加密处理,解压密码为:www.greenxf.com
感谢您对绿色先锋的支持,请将网站地址放在您的博客,空间等地方,以便我们为您及您的朋友提供更好的服务.
软件按字母排列:
中文按声母搜索:

我要回帖

更多关于 python 替换文件内容 的文章

 

随机推荐