字符串替换vb.net不工作

字符串替换vb.net不工作,vb.net,string,Vb.net,String,我做错了什么 If FilePath.ToLower().Contains(".pdf") Then Dim Replaced As String = FilePath.Replace("\","/") FilePath = "http:" & Replaced End If 例如,如果文件路径为\\sharepoint\file.pdf,则预期输出应为http://sharepoint/file.pdf。但是,实际输出是http:\\sharepoint\file.

我做错了什么

If FilePath.ToLower().Contains(".pdf") Then
    Dim Replaced As String = FilePath.Replace("\","/")
    FilePath = "http:" & Replaced
End If 
例如,如果文件路径为
\\sharepoint\file.pdf
,则预期输出应为
http://sharepoint/file.pdf
。但是,实际输出是http:\\sharepoint\file.pdf

更新1

这是原始字符串:

这是我的VB代码之后的样子:

如您所见,添加了http:part,但是没有触及反斜杠

更新2
这与斜杠有关。因为当我替换其他字符(例如,用@)时,被替换的字符串将正确显示。但不是斜杠

我仍然不明白为什么,但下面已经修复了我的代码:

Dim Replaced As String = FilePath
If FilePath.ToLower().Contains(".pdf") Then
    Replaced = FilePath.Replace("\","/")
    Replaced = "http:" & Replaced
End If 
然后在我使用的vbscript代码中

Sub toonDocument()
dim spobject
set spobject = CreateObject("Sharepoint.Document")
spobject.FilePath = "<% = Replaced %>"
spobject.openen()
set spobject = nothing
子文档()
暗淡对象
设置spobject=CreateObject(“Sharepoint.Document”)
spobject.FilePath=“”
spobject.openen()
设置spobject=nothing

所以
(而不是

我仍然不明白为什么,但是下面已经修复了我的代码:

Dim Replaced As String = FilePath
If FilePath.ToLower().Contains(".pdf") Then
    Replaced = FilePath.Replace("\","/")
    Replaced = "http:" & Replaced
End If 
然后在我使用的vbscript代码中

Sub toonDocument()
dim spobject
set spobject = CreateObject("Sharepoint.Document")
spobject.FilePath = "<% = Replaced %>"
spobject.openen()
set spobject = nothing
子文档()
暗淡对象
设置spobject=CreateObject(“Sharepoint.Document”)
spobject.FilePath=“”
spobject.openen()
设置spobject=nothing

所以
(而不是

您确定文件路径的开头包含:
\\sharepoint\file.pdf
?您如何测试输入/输出值?我尝试了您的代码,但无法复制。请检查:您是否按照描述定义了文件路径?与@forsvarir、@Alex相关,请参阅更新的问题。我添加了图片,以便您可以看到它确实发生了变化something@jao这段代码和相关问题中的代码都能正常工作。你的错误在别的地方,完全无关。我假设您将结果值丢弃在两者之间的某个位置。是否确定FilePath在开始时包含:
\\sharepoint\file.pdf
?您如何测试输入/输出值?我尝试了您的代码,但无法复制。请检查:您是否按照描述定义了文件路径?与@forsvarir、@Alex相关,请参阅更新的问题。我添加了图片,以便您可以看到它确实发生了变化something@jao这段代码和相关问题中的代码都能正常工作。你的错误在别的地方,完全无关。我假设您正在丢弃介于两者之间的某个结果值。