无法从变量中删除“Enter”

时间:2022-08-11 17:06:47

So the code I'm currently running will extract strings from slides in ppt, and some of these string may come with spaces or enters/line breaks. The code bellow is what I have, and it works great to remove spaces but it won't work for the Enters/line breaks.

所以我正在运行的代码将从ppt中的幻灯片中提取字符串,其中一些字符串可能带有空格或输入/换行符。下面的代码是我所拥有的,它可以很好地删除空格,但它不适用于Enters /换行符。

pptText = Shpe.TextFrame.TextRange
pptText = LCase(Replace(pptText," ",""))
pptText = Replace(pptText,vbNewLine,"")

When there is a text that has been input like this:

当有一个像这样输入的文本时:

iq_42, iq_26, iq_72

iq_42,iq_26,iq_72

In the debugger, the variable pptText will look like this:

在调试器中,变量pptText将如下所示:

pptText = iq_42, iq_26,iq_72

pptText = iq_42,iq_26,iq_72

But there is a character saved in that variable that the debugger isn't showing which messes with the rest of my program.

但是在该变量中保存了一个字符,调试器没有显示与我的程序的其余部分混淆。

I've tried Trim and Replace and I've tried using vbNewLine/vbCrLf/vbCr/vbLf to identify the Enter/line break without any success.

我尝试过修剪和替换,我尝试使用vbNewLine / vbCrLf / vbCr / vbLf来识别Enter /换行没有任何成功。

Any ideas on how to remove all traces of "enter"?

关于如何删除所有“进入”痕迹的任何想法?

2 个解决方案

#1


3  

You can try this:

你可以试试这个:

Edit

As wisely suggested by @Kostas K, here is the function version

正如@Kostas K明智地建议的那样,这是函数版本

Function RemoveEnter(ByVal YourString As String) As String
    RemoveEnter = Replace(Replace(Replace(YourString, vbCrLf, ""), vbCr, ""), vbLf, "")
End Function

#2


3  

Try this:

pptText = Replace(pptText, Chr$(10), "")

This replaces the newline character (CHAR(10) in Excel) with nothing. You can also do "Chr(10)". The dolla $ign just says "return this as a string value."

这将取代换行符(Excel中的CHAR(10))。你也可以做“Chr(10)”。 dolla $ ign只是说“将其作为字符串值返回”。

#1


3  

You can try this:

你可以试试这个:

Edit

As wisely suggested by @Kostas K, here is the function version

正如@Kostas K明智地建议的那样,这是函数版本

Function RemoveEnter(ByVal YourString As String) As String
    RemoveEnter = Replace(Replace(Replace(YourString, vbCrLf, ""), vbCr, ""), vbLf, "")
End Function

#2


3  

Try this:

pptText = Replace(pptText, Chr$(10), "")

This replaces the newline character (CHAR(10) in Excel) with nothing. You can also do "Chr(10)". The dolla $ign just says "return this as a string value."

这将取代换行符(Excel中的CHAR(10))。你也可以做“Chr(10)”。 dolla $ ign只是说“将其作为字符串值返回”。