1 | #Region "Microsoft.VisualBasic::32705ed3f0660ed3f17ce9a2c1ee4084, Microsoft.VisualBasic.Core\Extensions\StringHelpers\StringBuilders.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Module StringBuilders |
35 | ' |
36 | ' Function: (+2 Overloads) Replace |
37 | ' |
38 | ' /********************************************************************************/ |
39 | |
40 | #End Region |
41 | |
42 | Imports System.Runtime.CompilerServices |
43 | Imports System.Text |
44 | Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel |
45 | Imports Microsoft.VisualBasic.Linq |
46 | |
47 | ''' <summary> |
48 | ''' <see cref="StringBuilder"/> helpers |
49 | ''' </summary> |
50 | Public Module StringBuilders |
51 | |
52 | ''' <summary> |
53 | ''' 批量进行替换操作 |
54 | ''' </summary> |
55 | ''' <param name="sb"></param> |
56 | ''' <param name="replacements"></param> |
57 | ''' <returns></returns> |
58 | <Extension> |
59 | Public Function Replace(sb As StringBuilder, ParamArray replacements As NamedValue(Of String)()) As StringBuilder |
60 | For Each tuple As NamedValue(Of String) In replacements.SafeQuery |
61 | Call sb.Replace(tuple.Name, tuple.Value) |
62 | Next |
63 | |
64 | Return sb |
65 | End Function |
66 | |
67 | ''' <summary> |
68 | ''' 适用于更加复杂的结果值的产生的链式替换 |
69 | ''' </summary> |
70 | ''' <param name="sb"></param> |
71 | ''' <param name="find$"></param> |
72 | ''' <param name="value"></param> |
73 | ''' <returns></returns> |
74 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
75 | <Extension> |
76 | Public Function Replace(sb As StringBuilder, find$, value As Func(Of String)) As StringBuilder |
77 | Return sb.Replace(find, value()) |
78 | End Function |
79 | End Module |