C:\\上网\\上网记录\\bin\\Debug\\ding.wav;
如何把它改为相对路径?
C:\\上网\\上网记录\\bin\\Debug\\ding.wav;
如何把它改为相对路径?
操作系统:win98 编程工具:pVB 6.0 问题:我在编写一个HTML编辑器,但不知如何分析HTML语法中的文件的相对路径,例如: 当前目录: c:\site\subs\sub1\ 目标文件: c:\site\subs\images\logo.gif 那么 在html中应该写成: <img src="../images/logo.gif> 请问如何编写分析此类相对路径的语句?谢谢。 (disy) | |
sDict:当前目录 tDict:目标文件 函数返回值为转换后的目录 函数工作原理是: 当sDict不含盘符,而tDict含盘符时不转换。 当sDict和tDict盘符不相同时不转换。 当tDict为空时返回为空 其它情况时,先去掉各自的公共部分。然后对sDict余下部分进行循环,每含一个目录,则在tDict前加个"../"符号。 函数通过VB50测试正确 |
Private Function Convert_Dict()Function Convert_Dict(ByVal sDict As String, ByVal tDict As String) As String Dim i As Integer Convert_Dict = "" If InStr(tDict, "\") = 0 Then Convert_Dict = tDict Exit Function End If If tDict = "" Then Exit Function If sDict = "" Or (InStr(sDict, ":") = 0 And InStr(tDict, ":") > 0) Or (InStr(sDict, ":") > 0 _ And InStr(tDict, ":") > 0 And UCase(Left(sDict, 2)) <> UCase(Left(tDict, 2))) Then Convert_Dict = tDict Else sDict = IIf(Right(sDict, 1) = "\", sDict, sDict + "\") Do While UCase(Left(sDict, InStr(sDict, "\") - 1)) = UCase(Left(tDict, InStr(tDict, "\") - 1)) sDict = Right(sDict, Len(sDict) - InStr(sDict, "\")) tDict = Right(tDict, Len(tDict) - InStr(tDict, "\")) If sDict = "" Or InStr(tDict, "\") = 0 Then Exit Do Loop Do While InStr(sDict, "\") > 0 Convert_Dict = Convert_Dict + "../" sDict = Right(sDict, Len(sDict) - InStr(sDict, "\")) Loop Convert_Dict = Convert_Dict + tDict End If Do While InStr(Convert_Dict, "\") > 0 Convert_Dict = Left(Convert_Dict, InStr(Convert_Dict, "\") - 1) + "/" + Mid(Convert_Dict, _ InStr(Convert_Dict, "\") + 1, Len(Convert_Dict) - InStr(Convert_Dict, "\")) Loop End Function
会了吗?