| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1714 人关注过本帖
标题:文本文件查找替换问题
取消只看楼主 加入收藏
jiangyawen
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-8-31
收藏
得分:0 
对,只能有一个,只要有新的就覆盖掉旧的,如果一样就不做操作

2007-09-05 13:53
jiangyawen
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-8-31
收藏
得分:0 
我说的追加是如果文本里没有SIP Port :,那么就追加一条
上面说的是SIP Port :已经存在了,就要替换

2007-09-05 13:55
jiangyawen
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-8-31
收藏
得分:0 
对,就是这样,好崇拜你哦
谢谢!
太感激了!
要认你做老大!

2007-09-05 14:19
jiangyawen
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-8-31
收藏
得分:0 
为什么后面又设target="slore"呢
开始的 target = "SIP Port :"

2007-09-05 14:22
jiangyawen
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-8-31
收藏
得分:0 

Private Sub CmdApply_Click()
Dim Text1 As String
Dim Text2 As String
Dim Text3 As String
Dim Text4 As String
Dim Text5 As String
Dim Text6 As String
Dim Text8 As String
Dim Text9 As String
Text1 = "<SIP CONFIG MODULE>"
Text2 = "SIP Port :" & TextLocalSIPPort.Text
Text3 = "Stun Address :" & TextSTUNServerAddr.Text
Text4 = "Stun Port :" & TextSTUNServerPort.Text
Text5 = "Stun Effect Time :" & TextSTUNEffectTime.Text
Text6 = "--SIP Line List-- :"
Text8 = "SIP1 Use Stun :" & CheckUseStun.Value
Text9 = "SIP2 Use Stun :" & CheckUseStun1.Value
'text2的替换模块
Dim FileNum As Long
Dim StrLine As String
Dim StrFileContent As String
Dim target As String
'获取用户输入的要查找的字符串
target = "SIP Port :"
FileNum = FreeFile
Open ".\Config.txt" For Input As #FileNum
Do Until EOF(FileNum)
Line Input #FileNum, StrLine
If InStr(StrLine, target) > 0 Then StrLine = Text2: target = "Slore"
StrFileContent = StrFileContent & StrLine & vbCrLf
Loop
Close #FileNum
Open ".\Config.txt" For Output As #FileNum
Print #FileNum, StrFileContent
Close #FileNum
If target <> "Slore" Then '没有找到了匹配字符串
Open ".\config.txt" For Append As #FileNum
Print #FileNum, Text1
Print #FileNum, Text2
End If
Close #FileNum
'text3的替换模块

Dim StrFileContent1 As String
Dim target1 As String
'获取用户输入的要查找的字符串
target1 = "Stun Address :"
Open ".\Config.txt" For Input As #FileNum
Do Until EOF(FileNum)
Line Input #FileNum, StrLine
If InStr(StrLine, target) > 0 Then StrLine = Text3: target1 = "Slore1"
StrFileContent = StrFileContent & StrLine & vbCrLf
Loop
Close #FileNum
Open ".\Config.txt" For Output As #FileNum
Print #FileNum, StrFileContent
Close #FileNum
If target1 <> "Slore1" Then '没有找到了匹配字符串
Open ".\config.txt" For Append As #FileNum
Print #FileNum, Text3
End If
Close #FileNum
Unload Stun
End Sub


我想拓展可就是不行,反而把前面的都搞错了!
帮我看看行不?真不想麻烦你,可是我实在是没办法,你谅解下哈


2007-09-05 14:45
jiangyawen
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-8-31
收藏
得分:0 
回复:(jiangyawen)文本文件查找替换问题

Private Sub CmdApply_Click()
Dim Text1 As String
Dim Text2 As String
Dim Text3 As String
Dim Text4 As String
Dim Text5 As String
Dim Text6 As String
Dim Text8 As String
Dim Text9 As String
Text1 = "<SIP CONFIG MODULE>"
Text2 = "SIP Port :" & TextLocalSIPPort.Text
Text3 = "Stun Address :" & TextSTUNServerAddr.Text
Text4 = "Stun Port :" & TextSTUNServerPort.Text
Text5 = "Stun Effect Time :" & TextSTUNEffectTime.Text
Text6 = "--SIP Line List-- :"
Text8 = "SIP1 Use Stun :" & CheckUseStun.Value
Text9 = "SIP2 Use Stun :" & CheckUseStun1.Value
'text2的替换模块
Dim FileNum As Long
Dim StrLine As String
Dim StrFileContent As String
Dim target As String
'获取用户输入的要查找的字符串
target = "SIP Port :"
FileNum = FreeFile
Open ".\Config.txt" For Input As #FileNum
Do Until EOF(FileNum)
Line Input #FileNum, StrLine
If InStr(StrLine, target) > 0 Then StrLine = Text2: target = "Slore"
StrFileContent = StrFileContent & StrLine & vbCrLf
Loop
Close #FileNum
Open ".\Config.txt" For Output As #FileNum
Print #FileNum, StrFileContent
Close #FileNum
If target <> "Slore" Then '没有找到了匹配字符串
Open ".\config.txt" For Append As #FileNum
Print #FileNum, Text1
Print #FileNum, Text2
End If
Close #FileNum
'text3的替换模块
Dim target1 As String
'获取用户输入的要查找的字符串
target1 = "Stun Address :"
Open ".\Config.txt" For Input As #FileNum
Do Until EOF(FileNum)
Line Input #FileNum, StrLine
If InStr(StrLine, target1) > 0 Then StrLine = Text3: target1 = "Slore1"
StrFileContent = StrFileContent & StrLine & vbCrLf
Loop
Close #FileNum
Open ".\Config.txt" For Output As #FileNum
Print #FileNum, StrFileContent
Close #FileNum
If target1 <> "Slore1" Then '没有找到了匹配字符串
Open ".\config.txt" For Append As #FileNum
Print #FileNum, Text3
End If
Close #FileNum
Unload Stun
End Sub

修改了下最明显的错误,但结果还是一样!


2007-09-05 14:50
jiangyawen
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-8-31
收藏
得分:0 

<<VOIP CONFIG FILE>>Version:2.0002


<SIP CONFIG MODULE>
SIP Port :43

Stun Address :4325
可以了,但就是怎么才能变成
<<VOIP CONFIG FILE>>Version:2.0002

<SIP CONFIG MODULE>
SIP Port :43
Stun Address :4325
这个样子呢,就是在代码怎么会有这么多的换行呢?
奇怪


2007-09-05 14:54
快速回复:文本文件查找替换问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019130 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved