VB提取文本里的内容

VB提取文本里的内容,第1张

Dim p1 As Integer, p2 As Integer, srctxt As String, dsttxt As String

srctxt = "dasdasdsadffzdawdstarget=""_blank"">涵哥只是个传说</a>" '源字符串

p1 = InStr(1, srctxt, ">") + 1 '第一个>位置+1

p2 = InStr(1, srctxt, "</") '</的位置

If p1 > 0 And p2 > 0 And p1 < p2 Then

dsttxt = Mid(srctxt, p1, p2 - p1) '取>和</之间的字符串

MsgBox dsttxt

End If

上面这段代码可以做成一个function过程,输入参数是字符串,返回参数是中间值。

分类: 电脑/网络 >> 程序设计 >> 其他编程语言

问题描述:

这是一个学生的答题资料,要求取出其中的“Author Name :”“Site Name :”,以及“Student Name: ”等数据的值,请问要怎么实现?同时如果一个文本文件中存在多个学生的纪录(格式一样,接在这个学生纪录的后面)请问要怎么读出学生的资料,存入数据库中?

文件的内容是:

Author Name : O'Brien

Site Name : Introduction to Information Systems

Chapter : Chapter 1 : Foundations of Information Systems in Business

Quiz : Fill in the Blanks

Student Name: 0302159

Section ID: 030701

Results Reporter

================

Out of 4 questions, you answered 0 correctly

0 correct (0%)

4 incorrect (100%)

0 unanswered (0%)

=====================

=====================

Your Results :

=====================

Section :

INCORRECT

1 : The_____ponent of a system involves capturing and assembling elements that enter the system to be processed The correct answer is input Your answer is Neork card Feedback :

INCORRECT

2 : A system that has the ability to change itself or its environment in order to survive is referred to as a(n)_____system The correct answer is adaptive Your answer is information Feedback :

INCORRECT

3 : In the context of information systems, data is usually subjected to a "_____" process The fact that a customer's social security number is 123-45-6789 is an example of this The correct answer is value-added Your answer is hard Feedback :

INCORRECT

4 : The goal of_____is to help knowledge workers create, anize, and share important business knowledge wherever and whenever it is needed The correct answer is Knowledge management systems (KMS) Your answer is mis Feedback :

……(其他学生的考试资料)

我的QQ:

E-mail:wengzhan@163

解析:

先行行read

比如每行都放在str()中

则将str(0)到str(n)

做以下处理

a=split(str(i),":")

a(ubound(a))就是你想要的部分了

'楼上的代码,当文件最后有空行时会下标越界。

Dim Lines As String

Dim NextLine As String

Dim i As Integer

Open "d:\1txt" For Input As #1

Do While Not EOF(1)

Line Input #1, NextLine

Text1 = Text1 & Mid(NextLine, 1, 11) & vbCrLf

Text2 = Text2 & Mid(NextLine, 13, 8) & vbCrLf

Text3 = Text3 & Mid(NextLine, 22, 2) & vbCrLf

Loop

Close #1

首先需要加载需要获取网页文的网址,然后根据WebBrowser1documentbodyinnertext来获取文字,可参考下面部分代码

Private Sub cmdcommand1_click()

WebBrowser1navigate "具体网页地址"

End Sub

Private Sub webbrowser1_documentcomplete(ByVal pDisp As Object, URL As Variant)

txtText1 = WebBrowser1documentbodyinnertext

End Sub

这个不难,我先说思路。

一次性把文件内容独到一个字符串里

用你的

分隔符

将字符串分成字符串数组

分别赋值给标签(如果你的标签也是数组控件,将会更好。)

下面是代码:

Private

Sub

Command1_Click()

Dim

全部内容

As

String

Dim

分句内容

'注意,这个变量时变体类型

Open

"123txt"

For

Input

As

#1

'这里的123txt要加上文件的路径!!切记

Input

#1,

全部内容

Close

#1

分句内容

=

Split(全部内容,

"|")

Label1

=

分句内容(0)

Label2

=

分句内容(1)

Label3

=

分句内容(2)

'如果用了

控件数组

,以下三行改变为:

'For

i

=

0

To

UBound(分句内容)

'

Label1(i)

=

分句内容(i)

'Next

i

End

Sub

新建工程,在窗体中加入2个文本框一个命令按钮,点“工程”菜单——添加模块,在模块在代码窗口中输入下列代码:Type student_data '在模块中添加学生记录结构的定义name As String 12Sex As String 12End Type在窗体的代码窗口中输入下列代码:Private Sub Command1_Click()Dim student As student_dataDim filenumber As IntegerDim m_number As Integerfilenumber = FreeFileOpen C:\studenttxt For Random As #filenumber Len = Len(student)m_number = LOF(filenumber) / Len(student)studentname = Text1TextstudentSex = Text2TextPut #filenumber, m_number + 1, studentClose #filenumberEnd Sub每按一下命令按钮,在C:\studenttxt文件中都会添加一条记录,

Private

Sub

Command1_Click()

'基本读取方法---只能读取非中文

'

Dim

a

As

String,

b

As

String,

c

As

String,

d

As

String,

e

As

String,

f

As

String'定义几个变量

Dim

FileNo

As

Integer

FileNo

=

FreeFile()

'获取一个未使用的文件号

Dim

str

As

String

'用来记录最终的值

Open

"你要读取文件的完整路径"

For

Input

As

#FileNo

While

Not

EOF(FileNo)

Dim

str_Read

As

String

Input

#FileNo,

str_Read

'读取一个字符到变量str_Read---不包含换行回车符,也不包括逗号,分号及Tab,当读到分隔符号(前面列举的4种)时就赋值给后面的变量,如果有多个变量就读取相对应多的分隔数据

'如果为你的007txt文件且为你列举的内容那么上面一句就改成下面的语句

'

Input

#FileNo,

a,

b,

c,

d,

e,

f

'

str

=

str

&

str_Read

Wend

'MeText1Text

=

str

Close

#FileNo

End

Sub

1、实现上传按钮方法代码。

2、判断对象是否为空代码。

3、取得数据库字段 dtRows(0)("Pic")方法代码。

4、字节数组转换为Image类型方法代码。

5、处理SQL中 *** 作Image类型方法代码。

6、实现的上传结果。

以上就是关于VB提取文本里的内容全部的内容,包括:VB提取文本里的内容、在vb中如何读取文本文件中的指定内容、VB怎样读取指定的文本并显示等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9290495.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存