以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]替换剪贴板内容  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=121430)

--  作者:天一生水
--  发布时间:2018/7/6 8:05:00
--  [求助]替换剪贴板内容

窗口粘贴网页内容时,希望将除段落<p>以外的标签都过滤掉。

请老师帮助解决:

1、下面加黑的过滤标签代码,怎样修改;

2、代码放在哪里?

谢谢!

 

If ClipBoard.ContainsText Then     \'剪贴板替换
   Dim s As String = ClipBoard.GetText()
   Dim strText As String = System.Text.RegularExpressions.Regex.Replace(s, "<br>|<BR>|<br/>|<BR/>", chr(11))
   strText = System.Text.RegularExpressions.Regex.Replace(strText, "<[^>]+?>", "")
   strText = System.Text.RegularExpressions.Regex.Replace(strText, chr(11), "<br/>")

   s = strText
   \'Return strText            
End If

 


--  作者:有点甜
--  发布时间:2018/7/6 8:55:00
--  
Dim s As String = ClipBoard.GetText()
Dim strText As String = System.Text.RegularExpressions.Regex.Replace(s, "<br>|<BR>|<br/>|<BR/>", chr(11))
strText = System.Text.RegularExpressions.Regex.Replace(strText, "<p>|<P>", chr(254))
strText = System.Text.RegularExpressions.Regex.Replace(strText, "</p>|</P>", chr(255))
strText = System.Text.RegularExpressions.Regex.Replace(strText, "<[^>]+?>", "")
strText = System.Text.RegularExpressions.Regex.Replace(strText, chr(11), "<br/>")
strText = System.Text.RegularExpressions.Regex.Replace(strText, chr(254), "<p>")
strText = System.Text.RegularExpressions.Regex.Replace(strText, chr(255), "</p>")
msgbox(strText)

--  作者:有点甜
--  发布时间:2018/7/6 8:56:00
--  

可以写到keydown事件,加上

 

If e.keycode = keys.v andalso e.control = true Then


--  作者:天一生水
--  发布时间:2018/7/6 11:52:00
--  

老师,我放到窗口或窗口相应编辑控件的keydown事件里,运行没反应,也没有弹出窗口,是什么原因?

 

If e.keycode = keys.v andalso e.control = true Then

Dim s As String = ClipBoard.GetText()
Dim strText As String = System.Text.RegularExpressions.Regex.Replace(s, "<br>|<BR>|<br/>|<BR/>", chr(11))
strText = System.Text.RegularExpressions.Regex.Replace(strText, "<p>|<P>", chr(254))
strText = System.Text.RegularExpressions.Regex.Replace(strText, "</p>|</P>", chr(255))
strText = System.Text.RegularExpressions.Regex.Replace(strText, "<[^>]+?>", "")
strText = System.Text.RegularExpressions.Regex.Replace(strText, chr(11), "<br/>")
strText = System.Text.RegularExpressions.Regex.Replace(strText, chr(254), "<p>")
strText = System.Text.RegularExpressions.Regex.Replace(strText, chr(255), "</p>")
msgbox(strText)

s = strText

End if


--  作者:有点甜
--  发布时间:2018/7/6 12:07:00
--  

1、你的文本粘贴到哪里?

 

2、如果是textbox,只要你按下ctrl+v粘贴,绝对能触发。

 

3、如果要实时修改剪贴板内容,你应该写到timertick事件。