English 中文(简体)
利用VB6,我如何能够检查一个次扼制是在另一个扼杀的开始?
原标题:Using VB6, how can I check whether a sub-string is at the beginning of a another string?

我需要通过一个文本档案,并检查每条线路的开端是否始于“阿蒂鲁特”。 我如何在VB6中这样做?

最佳回答
Dim fso As New FileSystemObject
Dim ts As TextStream
Dim str As String

Set ts = fso.OpenTextFile(MyFile)
Do While Not ts.AtEndOfStream
    str = ts.ReadLine
    If InStr(str, "Attribute") = 1 Then
          do stuff
    End If
Loop
问题回答

使用了“Reex”。 您将须在您的参考资料中加入VB的定期表述图书馆。

Dim reg As new Scripting.Regex().
reg.Pattern = "^Attribute"
If reg.Match(line) Then
       Do Something
End If
Dim sInput As String, check as Boolean
check = true
Open "myfile" For INPUT As #txtFile
While Not EOF(txtFile)
   Input #txtFile, sInput
   If Not Mid(sInput,1,9) = "ATTRIBUTE" Then
       check = false
   End if
   sInput = ""
Wend
Close #txtFile

如果最终检查=真实情况,所有线都从“ATTRIBUTE”开始,否则就没有。

你们可以尝试这样的东西(没有测试的代码)——

Dim ParseDate, AllLinesStartWithAttribute, fso, fs
AllLinesStartWithAttribute = False
Set fso = CreateObject("Scripting.FileSystemObject")
Set fs = fso.OpenTextFile("c:yourfile", 1, True)
Do Until fs.AtEndOfStream
    If Left(fs.ReadLine, 9) <> "Attribute" Then
       AllLinesStartWithAttribute = False
       Exit Do
    End If
Loop
fs.Close
Set fs = Nothing

守则一旦实施,如果将<代码>AllLinesStartWithAttribute数值定为真实数值,那么你档案中的所有线就从Attribute开始。 请注意,该守则是敏感的。





相关问题
Prevent windows from queuing shellexecute requests

Win.ShellExecute 0, "open", "C:dirprogram.exe", "arguments", vbNullString, SW_SHOWNORMAL Win.ShellExecute 0, "open", "http://www.google.com", vbNullString, vbNullString, SW_SHOWNORMAL I want google....

Why is My Loop Only Deleting One File?

Using VB6 In a folder, i have n number of files, i want to delete a 0 kb files code Dim filename5 As String filename5 = Dir$(txtsourcedatabasefile & "*_*", vbDirectory) MsgBox filename5 Do ...

How to check the filesize?

Using VB6 I have the text file with different sizes, so i want to delete the file where filesize = 0 kb. How to make a vb6 code for deleting the 0 kb files. Need vb6 code Help

File Rename problem?

I m using VB6 and I have a folder where I have n number of files. I want to change the file extension to .txt. I used the code below to change the extension of all .fin files to .txt. Dim filename1 ...

Error 20728-F while in using Crystal Reports in VB6

I m using Crystal Reports in my VB6 project, but I m facing error while loading the report in crystalreport1.action=1; Please give me some solution for this problem. It is showing the error as Error ...

DllRegisterServer entry point was not found

When running my vb6 application I am getting error like, runtime error 53 : file not found: rscomclNoMsg.dll then i tried to register that dll from cmd line using regsvr32. Then I am getting ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签