100分的asp字符串替换问题
我弄一个ASP的页面读取论坛帖子内容,但是遇到图片读取不了显示为:[upload=jpg,13.jpg]UploadFile/2009-5/200959116529028...
我弄一个ASP的页面读取论坛帖子内容,但是遇到图片读取不了
显示为:[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]
想写个函数,替换一下字符,让它按标准格式显示出来
就是把[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]
变为
<img src="UploadFile/2009-5/2009591165290282.jpg" />
这样的话得把
[upload=jpg,13.jpg] 替换为<img src=",
[/upload]替换为" />
后面部分容易替换,关键是前面的[upload=***,***.***],因为不能预知图片类型,和图片名,不好搞
,所以希望大伙帮忙想下办法
我是想写个替换函数,问题是[upload=***,***.***]这部分不是可预知的,在程序里不知道怎么表示 展开
显示为:[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]
想写个函数,替换一下字符,让它按标准格式显示出来
就是把[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]
变为
<img src="UploadFile/2009-5/2009591165290282.jpg" />
这样的话得把
[upload=jpg,13.jpg] 替换为<img src=",
[/upload]替换为" />
后面部分容易替换,关键是前面的[upload=***,***.***],因为不能预知图片类型,和图片名,不好搞
,所以希望大伙帮忙想下办法
我是想写个替换函数,问题是[upload=***,***.***]这部分不是可预知的,在程序里不知道怎么表示 展开
展开全部
楼上给你的答案都是 替换掉 固定的字符串
但是你的图片文件名和长度 都是变化的
dim str as string
dim str1 as string
dim str2 as string
str = 路径字符串
str1 = Mid(str,InStr(str, 1, "]"),Len(str)-(InStr(str, 1, "]")+9))
str2="<img src="" & str1 & "" />"
str2 就是 你要的字符串
只是让你看看是不是 这么个思路 我没调试哦
有什么问题再联系吧!~~~~
VB 调试 成功的 : 思路你自己看看吧
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1950
ClientLeft = 60
ClientTop = 420
ClientWidth = 6480
LinkTopic = "Form1"
ScaleHeight = 1950
ScaleWidth = 6480
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 2400
TabIndex = 2
Top = 1320
Width = 1215
End
Begin VB.TextBox Text2
Height = 375
Left = 120
TabIndex = 1
Text = "Text2"
Top = 720
Width = 6255
End
Begin VB.TextBox Text1
Height = 375
Left = 120
TabIndex = 0
Text = "[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]"
Top = 120
Width = 6255
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim a As Long
Dim str As String
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String
str = Text1.Text
str3 = "<img src="""
str4 = """/> "
a = Int(InStr(1, str, "]") + 9)
str1 = Mid(str, InStr(1, str, "]") + 1, (Len(str) - (InStr(1, str, "]") + 9)))
str2 = str3 & str1 & str4
Text2.Text = str2
End Sub
但是你的图片文件名和长度 都是变化的
dim str as string
dim str1 as string
dim str2 as string
str = 路径字符串
str1 = Mid(str,InStr(str, 1, "]"),Len(str)-(InStr(str, 1, "]")+9))
str2="<img src="" & str1 & "" />"
str2 就是 你要的字符串
只是让你看看是不是 这么个思路 我没调试哦
有什么问题再联系吧!~~~~
VB 调试 成功的 : 思路你自己看看吧
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1950
ClientLeft = 60
ClientTop = 420
ClientWidth = 6480
LinkTopic = "Form1"
ScaleHeight = 1950
ScaleWidth = 6480
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 2400
TabIndex = 2
Top = 1320
Width = 1215
End
Begin VB.TextBox Text2
Height = 375
Left = 120
TabIndex = 1
Text = "Text2"
Top = 720
Width = 6255
End
Begin VB.TextBox Text1
Height = 375
Left = 120
TabIndex = 0
Text = "[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]"
Top = 120
Width = 6255
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim a As Long
Dim str As String
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String
str = Text1.Text
str3 = "<img src="""
str4 = """/> "
a = Int(InStr(1, str, "]") + 9)
str1 = Mid(str, InStr(1, str, "]") + 1, (Len(str) - (InStr(1, str, "]") + 9)))
str2 = str3 & str1 & str4
Text2.Text = str2
End Sub
展开全部
写个替换函数就可以啦
要写个正则替换
要写个正则替换
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%
str="[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]"
str=replace(replace(str,"[upload=jpg,13.jpg]",""),"[/upload]","")
%>
<img src="<%=str%>" />
复制下去运行一下,好用要给分哦
str="[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]"
str=replace(replace(str,"[upload=jpg,13.jpg]",""),"[/upload]","")
%>
<img src="<%=str%>" />
复制下去运行一下,好用要给分哦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
刚写的,asp代码实现
用了正则,可以替换变化字符,试试看吧=P
<%
Function ReplaceTest(str1,patrn, replStr)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
ReplaceTest = regEx.Replace(str1, replStr)
End Function
function RepUrl(sstr)
sstr=ReplaceTest (sstr,"\[up.*?\]","<img src=""")
RepUrl=ReplaceTest (sstr,"\[\/upload\]","""/>")
end function
response.write (RepUrl("[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]"))
%>
用了正则,可以替换变化字符,试试看吧=P
<%
Function ReplaceTest(str1,patrn, replStr)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
ReplaceTest = regEx.Replace(str1, replStr)
End Function
function RepUrl(sstr)
sstr=ReplaceTest (sstr,"\[up.*?\]","<img src=""")
RepUrl=ReplaceTest (sstr,"\[\/upload\]","""/>")
end function
response.write (RepUrl("[upload=jpg,13.jpg]UploadFile/2009-5/2009591165290282.jpg[/upload]"))
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询