VB删除 特定字符

变量S里存放了文字3454615368879879我76356爱4222346887987354351536百1536854645度85知345道435654<DTDTR... 变量S里存放了文字
3454615368879879
我76356爱4222346887987
354351536百1536854645度85知345道435654
<DTD
TR/">
3224
</style>

如何找S里的所有5度字样
从开头到最后出现5度的地方 包括5度
把“5度”后面的文字重新赋给S
S的内容我想再替换
这个字符<和>之间的的内容 包括<>全替换成空
里面也许含有回车 不是一段 替换完变量S就剩下
5度后面的“85知345道435654”和不在<>之间的3224

也许是我说的太复杂
意思就是说找特定字符 删除他和他前面的所以内容 然后删除<>和他之间的内容
先谢谢了
Private Sub Command1_Click()
Dim S As String
Dim sLine As String
lj = App.Path & "\" & Text1.Text & ".txt"
lj2 = App.Path & "\完成文件\" & Text1.Text & ".txt"
S = ""
If Dir(lj) = "" Then
Label1.Caption = lj & "文件不存在,跳过"
Else
Open lj For Input As #1
Do While Not EOF(1)
Line Input #1, sLine
S = S & sLine
Loop
Close #1

a = Split(Text2.Text, vbCrLf)
For i = 0 To UBound(a) - 1
S = Replace(S, a(i), "")
Next

S = Replace(S, vbCrLf, "")
S = Replace(S, " ", "")

Open lj2 For Output As #2
Print #2, S
Close #2
Label1.Caption = lj & "文件写入完成"
End If
Text1 = Text1 + 1
Text1.Text = Right("000" + Text1.Text, 3)
End Sub
Private Sub Form_Load()
On Error Resume Next
Text1.Text = "000"
Text2.Text = "t"
Command1.Caption = "替换"
MkDir (App.Path & "\完成文件\")
End Sub
帮我把您的代码加到我的代码里吗 谢谢了
我的这个是批量替换顺序文本用的 方便在MP4里看小说
yngsxx - 经理 四级 请问 下标越界怎么解决?这句代码太精妙了 不明白啊
展开
 我来答
百度网友c8b8bd133
2009-03-02 · TA获得超过305个赞
知道小有建树答主
回答量:165
采纳率:0%
帮助的人:217万
展开全部
Private Sub Command1_Click()
Dim S As String
Dim sLine As String
lj = App.Path & "\" & Text1.Text & ".txt"
lj2 = App.Path & "\完成文件\" & Text1.Text & ".txt"
S = ""
If Dir(lj) = "" Then
Label1.Caption = lj & "文件不存在,跳过"
Else
Open lj For Input As #1
Do While Not EOF(1)
Line Input #1, sLine
S = S & sLine
Loop
Close #1

a = Split(Text2.Text, vbCrLf)
For i = 0 To UBound(a) - 1
S = Replace(S, a(i), "")
Next

S = Replace(S, vbCrLf, "")
S = Replace(S, " ", "")

'********************************************
'加在此处
S = Split(Split(S, "5度")(1), "<")(0)
'********************************************
'说明,如果此处出现下标越界的话,说明你的S字符串并不是你题目中所说的格式,只要确保S字符串中,"5度"这个字符串存在,就不会出现了
'Split函数的意思,是将一个字符串以一定的分隔符分成若干个字符串并自动生成一个数组,举例: Split("24234a244a2fjeiata2456436","a2")就是将前面的字符串以a2为分隔符,这样就出现了"24234","44","fjeiat","456436"这四个小字符串的一个字符型数组,第一项对应下标为0,依此类推,假如你想得到第三个内容,也就是"fjeiat",则可以Split("24234a244a2fjeiata2456436","a2")(2)

Open lj2 For Output As #2
Print #2, S
Close #2
Label1.Caption = lj & "文件写入完成"
End If
Text1 = Text1 + 1 '因为是读取很多个顺序文件 比如这次000 下次就是001
Text1.Text = Right("000" + Text1.Text, 3)
End Sub

Private Sub Form_Load()
On Error Resume Next
Text1.Text = "000"
Text2.Text = "t"
Command1.Caption = "替换"
MkDir (App.Path & "\完成文件\")
End Sub
ljl88900
2009-02-25 · TA获得超过2660个赞
知道大有可为答主
回答量:2197
采纳率:100%
帮助的人:2599万
展开全部
把下面代码保存为Form1.frm,然后打开该文件,运行即可。

VERSION 5.00
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
ClientHeight = 2520
ClientLeft = 45
ClientTop = 435
ClientWidth = 6135
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2520
ScaleWidth = 6135
StartUpPosition = 2 '屏幕中心
Begin VB.TextBox Text1
Height = 2055
Left = 240
MultiLine = -1 'True
TabIndex = 1
Text = "Form1.frx":0000
Top = 240
Width = 2775
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 4560
TabIndex = 0
Top = 1800
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
Dim S As String, tmp As String, i, j
S = Text1.Text
i = InStr(1, S, "5度", vbTextCompare)
If i > 0 Then
S = Mid(S, i + 2)
End If
Do While InStr(S, "<") > 0
i = InStr(S, "<")
j = InStr(S, ">")
S = Left(S, i - 1) & Mid(S, j + 1)
Loop
S = Replace(S, vbNewLine, "")
MsgBox S
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式