使用正则表达式将文本从一个RichtextBox复制到另一个 [英] Copy a text from One RichtextBox to another using Regular Expresion

查看:120
本文介绍了使用正则表达式将文本从一个RichtextBox复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在根据正则表达式中给出的表达式将文本从一个richtextbox1复制到另一个richtextbox2时遇到问题.


Hi everyone,

I have a problem in copying a text from one richtextbox1 to another richtextbox2 based on the expression which we give in the regular expresssion.


<b>
    <FamilyId>587200256</FamilyId>
    <URN>05080100112010341</URN>
    <VernacularName>-</VernacularName>
    <FatherHusbandName>Sham Ram</FatherHusbandName>
    <HeadMemberId>1</HeadMemberId>
    <DoorHouseNo>-</DoorHouseNo>
    <VillageCode>01049400</VillageCode>
    <PanchayatTownCode>50872003</PanchayatTownCode>
    <BlockCode>0072</BlockCode>
    <DistrictCode>08</DistrictCode>
    <StateCode>05</StateCode>
    <BPLCitizen>01</BPLCitizen>
    <IsEnrolled>true</IsEnrolled>
    <EnrolledDateTime>2012-07-30T18:18:45.7+05:30</EnrolledDateTime>
    <IsCardPersonalized>false</IsCardPersonalized>
    <IsCardIssued>false</IsCardIssued>
    <IsExported>true</IsExported>
    <ExportDateTime>2012-08-14T17:46:43.957+05:30</ExportDateTime>
    <DigitalSignatureVerified>true</DigitalSignatureVerified>
    <SignedPersonalizationData>&#x0;&#x0;&#x0;&#x0;</SignedPersonalizationData>
    <RSBYType>99</RSBYType>
    <IsCardIssuedLastYear>false</IsCardIssuedLastYear>
    <CategoryCode>01</CategoryCode>
    <Minority>2</Minority>
    <PremiumStatus xml:space="preserve"> </PremiumStatus>
    <EKey>4D-18-D5-37-F8-61-83-10-C3-91-63-C3-2C-E0-D9-CD</EKey>
    <FontType>U</FontType>
    <FontName>Unicode</FontName>
    <OldURN>00083681051049404</OldURN>
    <EncryptedText>16BA9C9601BE8A750CBBF66DF89A4BF228AD69B3B11236482F282E65A72377489EE12DEC09FA6075</EncryptedText>
    <ExportedBatchNo>4295</ExportedBatchNo>
    <OperatorId>100002</OperatorId>
    <SystemName>SIRISHA</SystemName>
    <EnrollmentStationId>00:23:54:FF:B6:DF</EnrollmentStationId>
    <UploadStatus>N</UploadStatus>
    <UploadDateTime>2012-07-30T18:18:45.7+05:30</UploadDateTime>
  </b>

推荐答案

如果要从XML中提取文本并进行处理,请参见删除所有HTML标记,并仅在内部显示纯文本(以防XML格式不正确) [ ^ ].

如果要提取XML数据的特定部分,则可以尝试类似
If it''s about extracting some text from XML and process it, see http://support.microsoft.com/kb/317662[^].

If you insist on using Regex to extract all text from the XML, see Remove all the HTML tags and display a plain text only inside (in case XML is not well formed)[^].

If you want to extract a specific portion of the XML data, you may try something like
string xml = ...;
var match = Regex.Match(xml, @"<MyElement.*?>([\s\S]*?)</MyElement>");
string result = match.Success ? match.Group[1].Value : null;



您仍然面临文本可能包含xml实体的问题.这些将需要替换为相应的普通字符.这需要一些创造力.然后我将放弃正则表达式解决方案并使用xml dom方法,例如通过使用 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspx [ ^ ]并添加相应节点的内部文本.

干杯
安迪



You still face the problem that the text may contain xml entities. These would need to be replaced by the respective plain characters. This needs a bit of creativity. I would then discard the regex solution and use xml dom approach, e.g. by employing http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspx[^] and accesing the inner text of a respective node.

Cheers
Andi


这篇关于使用正则表达式将文本从一个RichtextBox复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆