麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 編程設計 > 正文

為Visual Studio 2010 增加多行查找與多行替換功能(VS跨行查找替換)

2020-07-14 13:22:59
字體:
來源:轉載
供稿:網友
小編長期都在使用Visual Studio這個全球最強大的IDE(沒有之一),但是有些時候,往往需要查找、或者是替換多行文本,這個時候,對于VS來說可能有點壓力了,因為默認的替換只能支持單行文本(雖然宏里面的FindLine是可以支持多行查找的,但是不能多行替換,稍后會詳細說明下)。

給 Visual Studio 2010 增加多行查找與多行替換功能(VS跨行查找替換:上篇)

給 Visual Studio 2010 增加多行查找與多行替換功能(VS跨行查找替換:上篇)

這個圖是增加多行查找與多行替換功能的效果圖,還不錯吧!

接下來,等小牛來介紹一下如何添加多行查找與多行替換功能?

只要幾個步驟就可加入功能。

1. 在 VS 中打開 Macros Explorer(宏 資源管理器) ,在 工具–宏–宏資源管理器(或者快捷鍵Alt+F8)。
2. 在 宏資源管理器 的 MyMacros 中新建一個宏 MultilineSearch
3. 雙擊 MultilineSearch ,則顯出 宏的IDE和生成的新宏的vb代碼
4. 把 新宏的vb代碼內容都刪除,把如下代碼拷進去

C# Code復制內容到剪貼板
  1. ’1. 在 vs.net 中 打開 Macros Explorer(宏 資源管理器) ,在 工具–宏–宏資源管理器。   
  2. ’2. 在 宏資源管理器 的 MyMacros 中新建一個宏 MultilineSearch   
  3. ’3. 雙擊 MultilineSearch ,則顯出 宏的IDE和生成的新宏的vb代碼   
  4. ’4. 把 新宏的vb代碼內容都刪除,把如下代碼拷進去   
  5. ’5. 將 System.Drawing.dll 加入 宏工程 的引用   
  6. ’6. 關閉宏IDE   
  7.     
  8. Imports EnvDTE   
  9. Imports System.Diagnostics   
  10. Public Module MultilineSearch   
  11. Sub MultilineSearchReplace()   
  12. Dim sf As New MultilineSearchForm   
  13. sf.ShowDialog()   
  14. If sf.result <> FindReplaceKind.none Then   
  15. ‘ temporarily disable Tools - Options -   
  16.             ‘ Environment - Documents - Initialize Find text from editor   
  17.             Dim oldFindInit As Boolean   
  18. Try   
  19. Dim props As EnvDTE.Properties   
  20. props = DTE.Properties(“Environment”, “Documents”)   
  21. Dim prop As EnvDTE.Property = props.Item(“FindReplaceInitializeFromEditor”)   
  22. oldFindInit = prop.Value   
  23. prop.Value = False   
  24. Catch ex As System.Exception   
  25. End Try   
  26. DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr   
  27. DTE.Find.FindWhat = sf.findText   
  28. DTE.Find.ReplaceWith = sf.replaceText   
  29. Select Case sf.result   
  30. Case FindReplaceKind.find   
  31. DTE.ExecuteCommand(“Edit.Find”)   
  32. Case FindReplaceKind.findInFiles   
  33. DTE.ExecuteCommand(“Edit.FindinFiles”)   
  34. Case FindReplaceKind.replace   
  35. DTE.ExecuteCommand(“Edit.Replace”)   
  36. Case FindReplaceKind.replaceInFiles   
  37. DTE.ExecuteCommand(“Edit.ReplaceinFiles”)   
  38. Case Else   
  39. End Select   
  40. ‘ restore Tools - Options -   
  41.             ‘ Environment - Documents - Initialize Find text from editor   
  42.             Try   
  43. Dim props As EnvDTE.Properties   
  44. props = DTE.Properties(“Environment”, “Documents”)   
  45. Dim prop As EnvDTE.Property = props.Item(“FindReplaceInitializeFromEditor”)   
  46. prop.Value = oldFindInit   
  47. Catch ex As System.Exception   
  48. End Try   
  49. End If   
  50. End Sub   
  51. End Module   
  52. ”’<summary>Types of find/replace operations.</summary>   
  53. Public Enum FindReplaceKind   
  54. ”’<summary>Find</summary>   
  55.     find   
  56. ”’<summary>Find In Files</summary>   
  57.     findInFiles   
  58. ”’<summary>Replace</summary>   
  59.     replace   
  60. ”’<summary>Replace in Files</summary>   
  61.     replaceInFiles   
  62. ”’<summary>None. Cancel was pressed.</summary>   
  63.     none   
  64. End Enum   
  65. Public Class MultilineSearchForm   
  66. Inherits System.Windows.Forms.Form  
  67. #Region “ Windows Form Designer generated code ”   
  68. Public Sub New()   
  69. MyBase.New()   
  70. ‘This call is required by the Windows Form Designer.   
  71.         InitializeComponent()   
  72. ‘Add any initialization after the InitializeComponent() call   
  73.     End Sub   
  74. ‘Form overrides dispose to clean up the component list.   
  75.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)   
  76. If disposing Then   
  77. If Not (components Is Nothing) Then   
  78. components.Dispose()   
  79. End If   
  80. End If   
  81. MyBase.Dispose(disposing)   
  82. End Sub   
  83. ‘Required by the Windows Form Designer   
  84.     Private components As System.ComponentModel.IContainer   
  85. ‘NOTE: The following procedure is required by the Windows Form Designer   
  86.     ‘It can be modified using the Windows Form Designer.   
  87.     ‘Do not modify it using the code editor.   
  88.     Friend WithEvents FindBox As System.Windows.Forms.TextBox   
  89. Friend WithEvents Label1 As System.Windows.Forms.Label   
  90. Friend WithEvents Label2 As System.Windows.Forms.Label   
  91. Friend WithEvents ReplaceBox As System.Windows.Forms.TextBox   
  92. Friend WithEvents FindBtn As System.Windows.Forms.Button   
  93. Friend WithEvents FindInFilesBtn As System.Windows.Forms.Button   
  94. Friend WithEvents ReplaceBtn As System.Windows.Forms.Button   
  95. Friend WithEvents ReplaceInFilesBtn As System.Windows.Forms.Button   
  96. Friend WithEvents CancelBtn As System.Windows.Forms.Button   
  97. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()   
  98. Me.FindBox = New System.Windows.Forms.TextBox   
  99. Me.Label1 = New System.Windows.Forms.Label   
  100. Me.Label2 = New System.Windows.Forms.Label   
  101. Me.ReplaceBox = New System.Windows.Forms.TextBox   
  102. Me.FindBtn = New System.Windows.Forms.Button   
  103. Me.FindInFilesBtn = New System.Windows.Forms.Button   
  104. Me.ReplaceBtn = New System.Windows.Forms.Button   
  105. Me.ReplaceInFilesBtn = New System.Windows.Forms.Button   
  106. Me.CancelBtn = New System.Windows.Forms.Button   
  107. Me.SuspendLayout()   
  108. ‘   
  109.         ‘FindBox   
  110.         ‘   
  111.         Me.FindBox.Location = New System.Drawing.Point(16, 24)   
  112. Me.FindBox.Multiline = True   
  113. Me.FindBox.Name = “FindBox”   
  114. Me.FindBox.ScrollBars = System.Windows.Forms.ScrollBars.Both   
  115. Me.FindBox.Size = New System.Drawing.Size(400, 80)   
  116. Me.FindBox.TabIndex = 0   
  117. Me.FindBox.Text = “”   
  118. ‘   
  119.         ‘Label1   
  120.         ‘   
  121.         Me.Label1.Location = New System.Drawing.Point(16, 8)   
  122. Me.Label1.Name = “Label1″   
  123. Me.Label1.Size = New System.Drawing.Size(160, 16)   
  124. Me.Label1.TabIndex = 2   
  125. Me.Label1.Text = “查找內容:”   
  126. ‘   
  127.         ‘Label2   
  128.         ‘   
  129.         Me.Label2.Location = New System.Drawing.Point(16, 112)   
  130. Me.Label2.Name = “Label2″   
  131. Me.Label2.Size = New System.Drawing.Size(160, 16)   
  132. Me.Label2.TabIndex = 4   
  133. Me.Label2.Text = “替換為:”   
  134. ‘   
  135.         ‘ReplaceBox   
  136.         ‘   
  137.         Me.ReplaceBox.Location = New System.Drawing.Point(16, 128)   
  138. Me.ReplaceBox.Multiline = True   
  139. Me.ReplaceBox.Name = “ReplaceBox”   
  140. Me.ReplaceBox.ScrollBars = System.Windows.Forms.ScrollBars.Both   
  141. Me.ReplaceBox.Size = New System.Drawing.Size(400, 80)   
  142. Me.ReplaceBox.TabIndex = 3   
  143. Me.ReplaceBox.Text = “”   
  144. ‘   
  145.         ‘FindBtn   
  146.         ‘   
  147.         Me.FindBtn.Location = New System.Drawing.Point(16, 232)   
  148. Me.FindBtn.Name = “FindBtn”   
  149. Me.FindBtn.Size = New System.Drawing.Size(80, 24)   
  150. Me.FindBtn.TabIndex = 5   
  151. Me.FindBtn.Text = “查找”   
  152. ‘   
  153.         ‘FindInFilesBtn   
  154.         ‘   
  155.         Me.FindInFilesBtn.Location = New System.Drawing.Point(104, 232)   
  156. Me.FindInFilesBtn.Name = “FindInFilesBtn”   
  157. Me.FindInFilesBtn.Size = New System.Drawing.Size(96, 24)   
  158. Me.FindInFilesBtn.TabIndex = 6   
  159. Me.FindInFilesBtn.Text = “在文件中查找”   
  160. ‘   
  161.         ‘ReplaceBtn   
  162.         ‘   
  163.         Me.ReplaceBtn.Location = New System.Drawing.Point(216, 232)   
  164. Me.ReplaceBtn.Name = “ReplaceBtn”   
  165. Me.ReplaceBtn.Size = New System.Drawing.Size(80, 24)   
  166. Me.ReplaceBtn.TabIndex = 7   
  167. Me.ReplaceBtn.Text = “替換”   
  168. ‘   
  169.         ‘ReplaceInFilesBtn   
  170.         ‘   
  171.         Me.ReplaceInFilesBtn.Location = New System.Drawing.Point(304, 232)   
  172. Me.ReplaceInFilesBtn.Name = “ReplaceInFilesBtn”   
  173. Me.ReplaceInFilesBtn.Size = New System.Drawing.Size(112, 24)   
  174. Me.ReplaceInFilesBtn.TabIndex = 8   
  175. Me.ReplaceInFilesBtn.Text = “在文件中替換”   
  176. ‘   
  177.         ‘CancelBtn   
  178.         ‘   
  179.         Me.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel   
  180. Me.CancelBtn.Location = New System.Drawing.Point(168, 272)   
  181. Me.CancelBtn.Name = “CancelBtn”   
  182. Me.CancelBtn.Size = New System.Drawing.Size(80, 24)   
  183. Me.CancelBtn.TabIndex = 9   
  184. Me.CancelBtn.Text = “取消”   
  185. ‘   
  186.         ‘MultilineSearchForm   
  187.         ‘   
  188.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)   
  189. Me.CancelButton = Me.CancelBtn   
  190. Me.ClientSize = New System.Drawing.Size(432, 310)   
  191. Me.Controls.Add(Me.CancelBtn)   
  192. Me.Controls.Add(Me.ReplaceInFilesBtn)   
  193. Me.Controls.Add(Me.ReplaceBtn)   
  194. Me.Controls.Add(Me.FindInFilesBtn)   
  195. Me.Controls.Add(Me.FindBtn)   
  196. Me.Controls.Add(Me.Label2)   
  197. Me.Controls.Add(Me.ReplaceBox)   
  198. Me.Controls.Add(Me.Label1)   
  199. Me.Controls.Add(Me.FindBox)   
  200. Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow   
  201. Me.Name = “MultilineSearchForm”   
  202. Me.Text = “多行查找與替換 - www.wuleba.com”   
  203. Me.ResumeLayout(False)   
  204. End Sub  
  205. #End Region  
  206. #Region “Properties”   
  207. Private m_result As FindReplaceKind = FindReplaceKind.none   
  208. ”’<summary>Gets result button from this dialog.</summary>   
  209.     ”’<value>The value specifying which button was pressed.</value>   
  210.     Public ReadOnly Property result() As FindReplaceKind   
  211. Get   
  212. Return m_result   
  213. End Get   
  214. End Property   
  215. Private m_findText As String   
  216. ”’<summary>Gets escaped multiline text to be searched.</summary>   
  217.     ”’<value></value>   
  218.     Public ReadOnly Property findText() As String   
  219. Get   
  220. Return m_findText   
  221. End Get   
  222. End Property   
  223. Private m_replaceText As String   
  224. ”’<summary>Gets escaped multiline replace text.</summary>   
  225.     ”’<value></value>   
  226.     Public ReadOnly Property replaceText() As String   
  227. Get   
  228. Return m_replaceText   
  229. End Get   
  230. End Property  
  231. #End Region   
  232. ”’<summary>Transforms the text to regular expression syntax.</summary>   
  233.     ”’<param name=”original”>Original text.</param>   
  234.     ”’<returns>Text with escaped regex characters.</returns>   
  235.     Private Function escapeRegEx(ByVal original As String) As String   
  236. Dim specialChars() As Char = “/.*+^___FCKpd___0gt;<[]|{}:@#()~”.ToCharArray   
  237. Dim c As Char   
  238. For Each c In specialChars   
  239. original = original.Replace(c.ToString, “/” & c.ToString)   
  240.         Next   
  241. original = original.Replace(vbCrLf, “/n”)   
  242. Return original   
  243. End Function   
  244. Private Sub MultilineSearchForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load   
  245. Try   
  246. Me.Activate()   
  247. Catch ex As System.Exception   
  248. End Try   
  249. End Sub   
  250. Private Sub CancelBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelBtn.Click   
  251. Try   
  252. m_result = FindReplaceKind.none   
  253. Me.Close()   
  254. Catch ex As System.Exception   
  255. End Try   
  256. End Sub   
  257. Private Sub FindBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindBtn.Click   
  258. Try   
  259. m_findText = escapeRegEx(Me.FindBox.Text)   
  260. m_replaceText = escapeRegEx(Me.ReplaceBox.Text)   
  261. m_result = FindReplaceKind.find   
  262. Me.Close()   
  263. Catch ex As System.Exception   
  264. End Try   
  265. End Sub   
  266. Private Sub FindInFilesBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindInFilesBtn.Click   
  267. Try   
  268. m_findText = escapeRegEx(Me.FindBox.Text)   
  269. m_replaceText = escapeRegEx(Me.ReplaceBox.Text)   
  270. m_result = FindReplaceKind.findInFiles   
  271. Me.Close()   
  272. Catch ex As System.Exception   
  273. End Try   
  274. End Sub   
  275. Private Sub ReplaceBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReplaceBtn.Click   
  276. Try   
  277. m_findText = escapeRegEx(Me.FindBox.Text)   
  278. m_replaceText = escapeRegEx(Me.ReplaceBox.Text)   
  279. m_result = FindReplaceKind.replace   
  280. Me.Close()   
  281. Catch ex As System.Exception   
  282. End Try   
  283. End Sub   
  284. Private Sub ReplaceInFilesBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReplaceInFilesBtn.Click   
  285. Try   
  286. m_findText = escapeRegEx(Me.FindBox.Text)   
  287. m_replaceText = escapeRegEx(Me.ReplaceBox.Text)   
  288. m_result = FindReplaceKind.replaceInFiles   
  289. Me.Close()   
  290. Catch ex As System.Exception   
  291. End Try   
  292. End Sub   
  293. End Class  

5. 將 System.Drawing.dll 加入 宏工程 的引用

給 Visual Studio 2010 增加多行查找與多行替換功能(VS跨行查找替換:上篇)

6. 關閉宏IDE

給 Visual Studio 2010 增加多行查找與多行替換功能(VS跨行查找替換:上篇)

操作完上面的6個步驟之后,你的VS2012就多了個多行搜索和替換文本的工具,效果圖就是最上面的那個圖。為了更方便大家學習,小牛打包了上面的這個vb代碼,需要的,可以自己下載。

吾樂吧軟件站補充說明:

小編在使用過程中發現,本文提供的這個方法雖然可以實現多行查找、多長替換文本,但是多行替換的時候,會出現一個問題:你不能把多行文本替換為多行文本(除非你手動寫正則)。為了解決這個問題,小編專門想出了另一個更加有效的方法,請大家移步查看《給 Visual Studio 2010 增加多行查找與多行替換功能(VS跨行查找替換:下篇)》

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 午夜视 | 在线免费av观看 | 一级美女大片 | www成人在线观看 | www久 | 成人男女啪啪免费观看网站四虎 | 免费在线观看国产精品 | 欧美黄色免费视频 | 九九热精品在线视频 | 午夜在线视频一区二区三区 | 中国妞xxxhd露脸偷拍视频 | 国产1区2区3区中文字幕 | av成人免费观看 | 久久久成人动漫 | 精品一区二区三区免费 | 十级毛片 | xp123精品视频 | 亚洲欧美国产高清 | 欧美一级淫片免费播放口 | 久久久日韩av免费观看下载 | 久久国产精品影视 | 国产午夜精品视频免费不卡69堂 | 龙的两根好大拔不出去h | 欧美一级aa免费毛片 | 黄污网站在线观看 | 婷婷中文字幕一区二区三区 | 国产精品久久久久久婷婷天堂 | 国产精品视频一区二区噜噜 | 免费国产视频在线观看 | 污版视频在线观看 | 国产人成精品一区二区三 | 欧美韩国日本在线 | 91精品国产刺激国语对白 | 黄色99视频 | 免费午夜视频 | 羞羞网站 | 欧美精品日日鲁夜夜添 | 成品片a免费直接观看 | 中文字幕一二区 | www.成人在线视频 | a一级黄|