特殊字符和字符串编辑

huangapple go评论60阅读模式
英文:

Special characters and string editing

问题

我正在尝试将Microsoft Word格式的文档转换为BBcode,以便轻松复制和粘贴。我找到了多个版本的方法,并对其中一些进行了调整以满足我的需求。目前,我正在尝试将一个段落从一种字体转换为BBcode可接受的字体。我找到了一行代码如下:

.Replacement.Text = "[font='Open Sans']^&[/font]"

这几乎完美地起作用,只是它包括了我需要消除的换行符,这样格式会更清晰一些。

但问题是,^& 是什么鬼东西?
我可以看到它的功能是将原始行引入,这很棒,因为我可以轻松添加BB标签(除了换行问题)。但是^&到底是什么东西。我找不到它的名称,以便可以查找替代方法或相关内容。

我的目标是研究这个东西,找出如何解决换行问题,但是我似乎无法弄清楚它到底是什么,以便进行研究。我的意思是,我在API中找不到它,搜索特殊字符也找不到相关结果。它不是通配符。它只是一种巧妙使用正则表达式的方式?

英文:

I am trying to convert microsoft word formatted document to BBcode for easy copy and paste reasons. I came across multiple versions of this and am tweeking some to my needs. Right now I am trying to convert a paragraph from one font to bb code acceptable font. I found a line of code like this.

.Replacement.Text = "[font="Open Sans"]^&[/font]"

this almost works perfectly, it just happens to include the line break which i need to figure out how to get rid of so the format is a little cleaner.

But the question is, what the hell is the ^&.
I can see its function pulls in the original line, which is awesome, because then I can easily add the BB tags. (minis the line break issue) But what the hell IS the ^&. I cannot figure out what it is called so I can look up alternatives or related things.

My goal is to research the thing and figure out how to get rid of my line break issue, but I can't seem to figure out what the hell it is to research it. I mean it isn't in the API that i can find, and searching for special characters is not google happy. It isn't a wildcard. It is just some clever use of regex?

答案1

得分: 1

有一个MS Word Find and Replace的功能,允许用户在搜索或替换文本中包含特殊字符/标记。这些字符看起来像^w^#,分别代表"任何空白字符"和"任何数字"。完整列表请参见此处

你遇到的这个特殊字符,^&,是用于重复查找文本的简写。当你希望将查找文本包含到替换文本中时,这会很有用,但查找文本也使用了通配符,可能在执行查找和替换之前不可知。

例如,对于查找"Gold"和替换"^&en",将替换所有的"Gold""Golden"。你也可以使用查找""<G[A-Za-z]{3}>"和替换"^&en"来不仅匹配"Gold",还匹配以"G"开头的任何4个字母单词,并在它们后面附加"en"

英文:

There is a feature with the MS Word Find and Replace to allow the user to include special characters/markers in either the search or replace text. Those characters look like ^w or ^#, for "any whitespace" and "any digit" respectively. See the full list here.

This special character that you've encountered, ^&, is the short-hand for repeating the find text. This can be handy when you want to include the find text into the replace text, but the find text is also using wildcards and might not be known until you execute the find & replace.

For example, a find and replace with find "Gold" and replace "^&en", would replace all "Gold" with "Golden". You could do the same find and replace with "<G[A-Za-z]{3}>" and "^&en" to not just match "Gold" but any 4-letter word starting with "G" and append them with "en".

huangapple
  • 本文由 发表于 2023年6月13日 03:53:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76459883.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定