我将以下文本存储在变量中myStringVariable
:
"
About this item
This fits your .
Make sure this fits by entering your model number.
"
抱歉,我不得不在""
上面显示通过VBA宏生成的单元格中的行首和行尾中断。
如何摆脱领先和落后的换行符,以获取以下信息:
About this item
This fits your .
Make sure this fits by entering your model number.
我不确定该如何处理。
编辑:
Replace(myStringVariable, vbNewLine, "")
将替换所有换行符。因此,我需要Trim
一种我认为是功能性的解决方案。
这是一个trimCHAR
与ExcelTRIM
功能类似的功能,不同之处在于您可以指定要TRIM的字符。
它会删除所有的开头和结尾char
,以及任何一倍 char
的字符串中(留下一个char
字符串中,如TRIM
用空格一样)
Function trimCHAR(ByVal S As String, char As String)
'similar to worksheet TRIM function except can specify character(s) to TRIM
Dim RE As Object
Dim I As Long
Set RE = CreateObject("vbscript.regexp")
With RE
.Global = True
.multiLine = True
'need to do separately, otherwise multiple chars within will
'be removed
.Pattern = char & "*$"
S = .Replace(S, "") 'Remove extra chars at end of string
.Pattern = char & "*([^" & char & "]" & char & ")*"
S = .Replace(S, "$1") 'Remove extra chars at start of string or within
End With
trimCHAR = S
End Function
原版的
工作表上的用法: =trimCHAR(cell_ref,CHAR(10))
在宏中,您可以使用 =trimChar(myStringVariable, vblf)
结果
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句