关于RichTextbox打开文本,进行编辑的问题,高手一定要进来呀,急!!!!!!!!!!!!!!!!!!!!!111

MuRongJun 2007-06-07 01:43:55
有一文本文件: 1.TXT
其内容如下:
1.号码:00008 fmto A/B 123123FSD1F23SD1FSD21FSD23
2.号码:00008 fmto A/B 123123FSD1F23SD1FSD21FSD23
3.号码:00008 fmto A/B 123123FSD1F23SD1FSD21FSD23
4.号码:00023 fmto A/B 12321313
5.号码:00023 fmto A/B 12321313
6.号码:00024 fmto A/B 1321546431641234WER6516546131316456456
7.号码:00024 fmto A/B 1321546431641234WER6516546131316456456
8.号码:00024 fmto A/B 1321546431641234WER6516546131316456456
9.号码:00024 fmto A/B 1321546431641234WER6516546131316456456
10.号码:00025 fmto A/B 110
11.号码:00027 fmto A/B 1321546431641234651GFDGDF6546131316456456
12.号码:00027 fmto A/B 1321546431641234651GFDGDF6546131316456456
13.号码:00028 fmto A/B 1321546431641234651GFDGDF6546131316456456
14.号码:00029 fmto A/B 123456789
15.号码:00029 fmto A/B 123456789
16.号码:00029 fmto A/B 123456789
17.号码:00130 fmto A/B ASD
18.号码:00130 fmto A/B ASD
19.号码:00130 fmto A/B ASD
20.号码:00130 fmto A/B ASD

想实现功能:在VB中用richtextbox控件打开上述文本文件,然后把文本中重复的项删除掉,如

1.号码:00008 fmto A/B 123123FSD1F23SD1FSD21FSD23
2.号码:00008 fmto A/B 123123FSD1F23SD1FSD21FSD23
3.号码:00008 fmto A/B 123123FSD1F23SD1FSD21FSD23

删除后为:
1.号码:00008 fmto A/B 123123FSD1F23SD1FSD21FSD23

然后但保存文本文件
...全文
241 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
CathySun118 2007-06-07
  • 打赏
  • 举报
回复
把文本文件当做数据库处理,方便查询、删除
浪客 2007-06-07
  • 打赏
  • 举报
回复
楼上正解。
zzyong00 2007-06-07
  • 打赏
  • 举报
回复
VBToy说的对
VBAdvisor 2007-06-07
  • 打赏
  • 举报
回复
'Delete Textbox a Line,LineIndex从0开始

Private Sub DelLine(txtEditor As TextBoxEx, ByVal LineIndex As Long)
'Deletes the specified line from the textbox
Dim lngSelStart As Long 'used to save the caret position
Dim lngLineLen As Long 'the length of the line to delete
Dim lngCharPos As Long 'the index of the first character on the line
Dim LineCount As Long

LineCount = SendMessage(txtEditor.hWnd,EM_GETLINECOUNT, 0&, 0&)

If LineIndex >= LineCount Then
Exit Sub
End If
lngSelStart = txtEditor.SelStart

If LineIndex < LineCount Then
lngCharPos = SendMessage(txtEditor.hWnd,EM_LINEINDEX, LineIndex, 0&)
End If

lngLineLen = SendMessage(txtEditor.hWnd, EM_LINELENGTH, lngCharPos, 0&)

txtEditor.Text = Left$(txtEditor.Text, lngCharPos) & Mid$(txtEditor.Text, lngCharPos + lngLineLen + 1)

txtEditor.SelStart = lngSelStart

End Sub

'Textbox 返回第N行的中文文字

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Const EM_GETLINE = &HC4
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINELENGTH = &HC1

'获得Textbox Line String
Public Function GetLineText(txtEditor As TextBoxEx, ByVal LineIndex As Long) As String

Dim LineText() As Byte
Dim size As Long
Dim pos As Long

pos = SendMessage(txtEditor.hwnd, EM_LINEINDEX, LineIndex, 0)
size = SendMessage(txtEditor.hwnd, EM_LINELENGTH, pos, 0)
If size = 0 Then
GetLineText = vbnullstring
Else
ReDim LineText((size - 1) + 1)
CopyMemory LineText(0), size, 2
size = SendMessage(txtEditor.hwnd, EM_GETLINE, LineIndex, LineText(0))
GetLineText = StrConv(LeftB(LineText, size), vbUnicode)
End If

End Function

VBToy 2007-06-07
  • 打赏
  • 举报
回复
这和用哪种控件显示无关,也就是字符串处理问题。可以定义一个字符串数组,读取一行数,在字符串数组中找查是否已有该行数据,如果没有,存入数组,再读下一行...最后将字符串数组中的数据保存成txt文件。
VBAdvisor 2007-06-07
  • 打赏
  • 举报
回复
用Textbox就行了,为什么要用richtextbox?

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧