- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我检查了很多关于在 vba 中修剪前导和尾随空格的建议(顺便说一下,excel)。
我找到了这个解决方案,但它也修剪了 å ä ö (也是大写),而且我在正则表达式方面太弱,看不出原因:
Function MultilineTrim (Byval TextData)
Dim textRegExp
Set textRegExp = new regexp
textRegExp.Pattern = "\s{0,}(\S{1}[\s,\S]*\S{1})\s{0,}"
textRegExp.Global = False
textRegExp.IgnoreCase = True
textRegExp.Multiline = True
If textRegExp.Test (TextData) Then
MultilineTrim = textRegExp.Replace (TextData, "$1")
Else
MultilineTrim = ""
End If
End Function
(这是来自 SO 的答案,其中用户帐户似乎处于非事件状态:
https://stackoverflow.com/a/1606433/3701019)
因此,如果有人可以帮助解决(a)问题的替代解决方案或(b)不会删除(单个)åäö字符的正则表达式/代码版本,我会很高兴。
感谢您的帮助!
详细信息:问题
我的上下文是 vba 中的 xmlparser,它获取要解析的 xml block 。有时它只是从流中获取一个字符,可能是 å ä ö,然后该函数将其完全剥离。
当然,我很乐意澄清或编辑这个问题。
仅供引用:我已经根据答案准确分享了我所做的事情,请参见下文。
最佳答案
对于正则表达式,我会使用:
^[\s\xA0]+|[\s\xA0]+$
这将匹配 HTML 文档中常见的“常见”空白字符以及 NBSP。
VBA 代码如下所示,其中 S 是要修剪的行:
Dim RE as Object, ResultString as String
Set RE = CreateObject("vbscript.regexp")
RE.MultiLine = True
RE.Global = True
RE.Pattern = "^[\s\xA0]+|[\s\xA0]+$"
ResultString = RE.Replace(S, "")
以及正则表达式的解释:
Trim whitespace at the start and the end of each line
-----------------------------------------------------
^[\s\xA0]+|[\s\xA0]+$
Options: ^$ match at line breaks
Match this alternative (attempting the next alternative only if this one fails) «^[\s\xA0]+»
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match a single character present in the list below «[\s\xA0]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A “whitespace character” (ASCII space, tab, line feed, carriage return, vertical tab, form feed) «\s»
The character with position 0xA0 (160 decimal) in the character set «\xA0»
Or match this alternative (the entire match attempt fails if this one fails to match) «[\s\xA0]+$»
Match a single character present in the list below «[\s\xA0]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A “whitespace character” (ASCII space, tab, line feed, carriage return, vertical tab, form feed) «\s»
The character with position 0xA0 (160 decimal) in the character set «\xA0»
Assert position at the end of a line (at the end of the string or before a line break character) «$»
Created with RegexBuddy
关于regex - vba中修剪前导和尾随空格的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24048400/
考虑 this link来自 Bit Twiddling Hacks 网站。为了计算尾随位,使用了以下算法: unsigned int v; // 32-bit word input to
我正在开发一个在输出目录中创建多个文件的 makefile。为了创建这些文件,输出目录需要已经存在,否则文件创建失败。 这是一个演示我遇到的问题的最小示例: .PHONY: default defau
我试图让 TextField 的值以尾随对齐方式显示。 如您所见,值 34.3 以前导对齐方式显示。 我确信我遗漏了一些明显的东西,但我不知道是什么。有什么想法吗? @State private va
我想让我的 StackView 在屏幕上居中,并在每边(左和右)添加一个 20 的填充以获得屏幕边距: 但不考虑左边距: 结果如下: 如何处理右边距?对于其他类型的对象(不是 StackView),我
我们在我们的网站上使用漂亮的网址。几年前我有一个外部技术人员添加反向链接。他做得很好,但在一个案例中,他总是添加一个尾随空格字符的链接。 https://www.example.com/item/it
我正在设计一个带前缀的可变长度整数。 Rust 具有计算前导和尾随 1 和 0 的方法:https://doc.rust-lang.org/std/primitive.u64.html#method.
Passing a lambda to the last parameter In Kotlin, there is a convention that if the last parameter o
我需要正则表达式的帮助来从字符串中去除不需要的字符(在 Java 中)。我用 4 个正则表达式解决了这个问题。替换将被多次调用 [peeks: 50+ times/sec] 它并降低性能。但我认为它肯
如果我用 base64 编码一个由七个字符组成的字符串,例如abcdefg 与网站 https://www.base64encode.org/结果是 YWJjZGVmZw==。尾部的“==”字符被填充
尝试在客户端上使用 sprintf 打印出包含缓冲区的 char[]。最后一个字符是“\0”。这是我的服务器代码: char buffer[MAXDATASIZE]; char res[MAXDATA
我在 angular2 项目中遇到问题,我正在生成一个要通过电子邮件发送给用户的 URL。电子邮件中的 URL 需要包含一个特殊 ID,该 ID 在路由器中传递为: { 路径:somepath/:id
我正在尝试删除所有前导和尾随 在使用 PHP 的字符串中。 举个例子 Hello World This is a message... 我想回去 Hello World This is a mes
我有一个 JSON 输出,我想稍微修改一下: JSON={"type":"global", "elements":[ {"type":"car","model":"bmw", "element
继续阅读 ranges-v3 库,我意识到所有关于模板类型有效表达式的检查都有一个尾部 ", 42"表达式,我想知道这样做的目的是什么。例如: namespace concepts { con
我使用的是最新版本的 Xcode (11 Beta 16) 和 macOS (10.15 Beta 6) 我正在尝试创建两个 View 。从第一个 View ,您应该能够通过尾随导航栏项目导航到第二个
我在使用 SwiftUI 时遇到性能问题 List有大量数据。我创建了一个演示应用程序只是为了展示 500_000 String 的问题s 并显示其中一个的尾随 Action ,CPU 将在几秒钟内达
我正在使用 Blue River 的最新 docker 镜像,运行 docker-compose 启动它并在 Mura CMS 中部署一个站点包。 问题是,当我访问 URL 后面没有正斜杠的页面时,我
我是一名优秀的程序员,十分优秀!