vb怎么提取文本文件每行字符串中指定字符
VB6.0使用Mid 函数来读取字符串中指定数量的字符。
Mid 函数:返回 Variant (String),其中包含字符串中指定数量的字符。
语法:Mid 函数示例:本示例使用 Mid 语句来得到某个字符串中的几个字符。
Dim MyString, FirstWord, LastWord, MidWordsMyString = "Mid Function Demo" 建立一个字符串。
FirstWord = Mid(MyString, 1, 3) ' 返回 "Mid"。
LastWord = Mid(MyString, 14, 4) ' 返回 "Demo"。
MidWords = Mid(MyString, 5) ' 返回 "Funcion Demo"。
VB中提取WORD的文字并复制到另外一个WORD吗。
是直接复制整个...
读写EXCEL表:展开全部1、在工程中引用Microsoft Excel类型库: 从"工程"菜单中选择"引用"栏;选择Microsoft Excel 12.0 Object Library(EXCEL2007),然后选择"确定"。
表示在工程中要引用EXCEL类型库。
2、在通用对象的声明过程中定义EXCEL对象: Dim xlApp As Excel.Application Dim xlBook As Excel.WorkBook Dim xlSheet As Excel.Worksheet 3、在程序中操作EXCEL表常用命令: Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象 Set xlBook = xlApp.Workbooks.Open("文件名") '打开已经存在的EXCEL工件簿文件 Set xlBook = xlApp.Workbooks.Add("文件名") '创建新的EXCEL工件簿文件 xlApp.Visible = True '设置EXCEL对象可见(或不可见) Set xlSheet = xlBook.Worksheets("表名") '设置活动工作表 for i=1 to 100for j=1 to 50numArr(j,i)=xlSheet.Cells(j, i) '......................................nextnextxlBook.Close (True) '关闭工作簿 xlApp.Quit '结束EXCEL对象 Set xlApp = Nothing '释放xlApp对象张志晨...
用VBA快速获取word大纲文本
Private Sub Command1_Click()Call maxlength(Text1, n)Text2 = nEnd SubSub maxlength(s, maxword)maxword = ""For n = 1 To 10000i = InStr(s, " ")If i = 0 And Len(s) > 0 Then i = Len(s) + 1word = Left(s, i - 1)If Len(word) > Len(maxword) Thenmaxword = wordEnd IfIf i >= Len(s) Then Exit Fors = Right(s, Len(s) - i)Next nEnd Sub
如何用VB.net 读写Unicode编码的文本
不要用do until,用for:Dim arr() As String, i As Integerarr = Split(r.ReadLine, " ")For i = LBound(arr) To UBound(arr)MsgBox(arr(i))Next--------------------还是用readline,如果你要提取两个非连续空格之间的字符串,可以用Dim arr() As Stringarr = Split(r.ReadLine, " ")arr()数组里就存了你要的单词。
快要下班了,明后天不上班,如果16:30之前还搞不定就要下个星期1了。
----------------------------------哈,是我的失误没想到还有可能有半角的日文。
用utf-8就OK了,代码如下:(文本文件存的时候不能存成ansi,要存成utf-8,或是Unicode)Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim r As System.IO.StreamReaderr = New System.IO.StreamReader("c:\a.txt", System.Text.Encoding.GetEncoding("utf-8"))Do While Not r.EndOfStreamMsgBox(r.ReadLine)LoopEnd Sub
VB下标越界,怎么解决?
Option Base 1Option ExplicitDim words() As StringPrivate Sub Command1_Click() Dim st As String, i As Integer st = LCase(Text1) Call choice(st) st = "" For i = 1 To UBound(words) st = st & words(i) & " " Next i st = Left(st, Len(st) - 1) & "."Text2 = UCase(Left(st, 1)) & Mid(st, 2) End Sub Sub choice(s As String)Dim st As String, i As Integer, k As Integer, p As String, d() As Stringk = 0If Right(s, 1) <> " " Then s = s & " "For i = 1 To Len(s)st = Mid(s, i, 1)If st >= "a" And st <= "z" Thenp = p & stElseIf st = " " Thenk = k + 1ReDim Preserve d(k)d(k) = pp = ""End IfNextReDim Preserve words(UBound(d)) As Stringwords = dEnd Sub提出2点是:1.重新定义一个动态数组要用ReDim Preserve才能保留数组原有的内容,如果仅用ReDim则会清空数组内容。
2.Sub是没有返回值的,所以如你所写的Sub不会有任何作用,必须通过赋值来取得需要的结果。
转载请注明出处51数据库 » vb 提取word中字符串