本文共 7765 字,大约阅读时间需要 25 分钟。
c# word中替换字符
In addition to searching and replacing text, Word lets you search for special characters—tabs, indents, paragraph marks, and so on—and then replace them with other special characters. This can be handy for quick and easy changes which would typically take you a bit more time to do manually.
除了搜索和替换文本外,Word还允许您搜索特殊字符(制表符,缩进,段落标记等),然后将其替换为其他特殊字符。 快速方便地进行更改非常方便,通常需要您多花点时间进行手动操作。
To understand when searching and replacing special characters may be useful, let’s look at some examples.
为了了解在搜索和替换特殊字符时可能有用的方法,我们来看一些示例。
There are too many special characters to detail all of them, but let’s take a look at a few general examples of how searching and replacing those characters works.
有太多特殊字符无法详细说明所有这些字符,但让我们看一些有关如何搜索和替换这些字符的一般示例。
Let’s say your document looks something like this:
假设您的文档看起来像这样:
Note: If you don’t see the special characters in your document, you can turn them on by clicking the Show/Hide button on the Ribbon. Its icon looks like the paragraph symbol.
注意:如果在文档中看不到特殊字符,可以通过单击功能区上的“显示/隐藏”按钮将其打开。 其图标看起来像段落符号。
You need to replace every occurrence of the word “Section” with a section symbol. Switch over to the “Home” tab on Word’s Ribbon and then click “Replace.” Alternatively, you can press Ctrl+H.
您需要将每次出现的“节”替换为节符号。 切换到Word功能区上的“主页”选项卡,然后单击“替换”。 或者,您可以按Ctrl + H。
Type the word “Section” into the “Find What” box and then click the “More >>” button to expand the Find and Replace options.
在“查找内容”框中键入单词“ Section”,然后单击“更多>>”按钮以展开“查找和替换”选项。
Click in the “Replace With” box to put your insertion point there and then click the “Special” button.
单击“替换为”框,将插入点放在此处,然后单击“特殊”按钮。
Click “Section Character” from the dropdown list.
从下拉列表中单击“部分字符”。
Notice that the “Replace With” box now contains the text “^%”—this is Word’s code for that section symbol. Click the “Replace All” button. In this example, 16 replacements were made. Click the “OK” button and then close the Find and Replace window.
注意,“替换为”框现在包含文本“ ^%”,这是该节符号的Word代码。 点击“全部替换”按钮。 在此示例中,进行了16次替换。 单击“确定”按钮,然后关闭“查找和替换”窗口。
All occurrences of the word “Section” have now been replaced with the section character.
现在,所有出现的“ Section”一词都已替换为section字符。
For this next example, notice there are quite a few hyphenated words in our sample paragraph, including three occurrences where the hyphenated words are separated on different lines. Let’s replace all the regular hyphens with non-breaking hyphens so that doesn’t happen.
对于下一个示例,请注意在我们的示例段落中有很多连字符,包括三个出现的连字符在不同行上分开的情况。 让我们用不间断的连字符替换所有常规的连字符,以免发生这种情况。
On the “Home” tab, click “Replace” or just press Ctrl+H.
在“主页”选项卡上,单击“替换”,或仅按Ctrl + H。
In the “Find What” box, delete any existing text or characters and then type a single hyphen character. Click the “More >>” button if needed to expand the Find and Replace options.
在“查找内容”框中,删除任何现有的文本或字符,然后键入一个连字符。 如果需要,请单击“更多>>”按钮以展开“查找和替换”选项。
Click in the “Replace With” box to put your insertion point there. Delete any existing text or characters and then click the “Special” button.
单击“替换为”框,将您的插入点放在此处。 删除任何现有的文本或字符,然后单击“特殊”按钮。
Click “Nonbreaking Hyphen” from the dropdown list.
从下拉列表中单击“不间断的连字符”。
Notice that Word’s code for the nonbreaking hyphen—“^~”— has now been added to the “Replace With” box. Click the “Replace All” button. In this example, 11 replacements were made. Click the “OK” button and then close the Find and Replace window.
请注意,Word的不间断连字符-“ ^〜”-现在已添加到“替换为”框中。 点击“全部替换”按钮。 在此示例中,进行了11次替换。 单击“确定”按钮,然后关闭“查找和替换”窗口。
Word has replaced all hyphens with nonbreaking hyphens. Notice the hyphenated words on the right margin are no longer separated.
Word已将所有连字符替换为不间断的连字符。 请注意,右边距处的连字符不再分开。
In this example, we want to replace any double paragraph marks with a single paragraph mark, removing the extra spacing between paragraphs.
在此示例中,我们希望将任何双段标记替换为单个段标记,从而消除段之间的多余间距。
On the “Home” tab, click the “Replace” button. Alternatively, you can press Ctrl+H.
在“主页”选项卡上,单击“替换”按钮。 或者,您可以按Ctrl + H。
Click in the “Find What” box and then delete any existing text or characters. Click the “More>>” button to open up the additional options, click the “Special” button, and then click the “Paragraph Mark” option from the dropdown list.
单击“查找内容”框,然后删除任何现有的文本或字符。 单击“更多>>”按钮以打开其他选项,单击“特殊”按钮,然后从下拉列表中单击“段落标记”选项。
Notice that Word’s code for a paragraph mark (“^v”) has been inserted into the “Find What” box. Click the “Special” button again and then click “Paragraph Mark” again from the dropdown list to place a second paragraph mark there. (Note that you could also just type “^v^v” into the box yourself if you’re already familiar with the codes.)
请注意,段落标记(“ ^ v”)的Word代码已插入“查找内容”框中。 再次单击“特殊”按钮,然后再次从下拉列表中单击“段落标记”以在其中放置第二个段落标记。 (请注意,如果您已经熟悉代码,也可以自己在框中输入“ ^ v ^ v”。)
There are now two paragraph marks in the Find what box. Click in the “Replace With” box, delete any existing text or characters, and then click the “Special” button. On the dropdown menu, choose “Paragraph Mark.”
现在,在“查找内容”框中有两个段落标记。 单击“替换为”框中,删除任何现有的文本或字符,然后单击“特殊”按钮。 在下拉菜单上,选择“段落标记”。
For the final step, click the “Replace All” button. In this example, Word made eight replacements. Click the “OK” button and then close the Find and Replace window.
对于最后一步,单击“全部替换”按钮。 在此示例中,Word进行了八次替换。 单击“确定”按钮,然后关闭“查找和替换”窗口。
All occurrences of two paragraph marks have been replaced with one paragraph mark.
所有出现的两个段落标记都已替换为一个段落标记。
As you can see, using Find and Replace can save you lots of time when replacing special characters in your documents. And we’ve just scratched the surface here. There are more special characters waiting on that menu for you to explore.
如您所见,当替换文档中的特殊字符时,使用“查找并替换”可以节省大量时间。 我们只是在这里刮了一下表面。 该菜单上还有更多特殊字符供您浏览。
翻译自:
c# word中替换字符
转载地址:http://bjzwd.baihongyu.com/