Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
How to search for a string in a text
Logged in as: Guest
arrSession:exec spGetSession 2,2,63374
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
WSH & Client Side VBScript
>> How to search for a string in a text
Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page:
[1]
Login
Message
<< Older Topic
Newer Topic >>
How to search for a string in a text -
8/12/2008 7:09:48 AM
borges__writer
Posts: 1
Score: 0
Joined: 8/12/2008
Status:
offline
This seems pretty simple but I'm new to VBS.
If I want to find say string "JOHN" in a .txt file or simply verify that it's present or not. What would be the most efficient way to do this?
Thanks!
< Message edited by
borges__writer
--
8/12/2008 7:31:07 AM
>
Post #: 1
RE: How to search for a string in a text -
8/12/2008 7:31:43 AM
dm_4ever
Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status:
offline
Search for
FileSystemObject
OpenTextFile
InStr
_____________________________
dm_4ever
My philosophy:
K.I.S.S - Keep It Simple Stupid
Read Me:
http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff:
http://www.visualbasicscript.com/m_47117/tm.htm
(in reply to
borges__writer
)
Post #: 2
RE: How to search for a string in a text -
8/14/2008 5:48:00 AM
chiltz
Posts: 76
Score: 0
Joined: 6/13/2007
Status:
offline
Option Explicit Dim objFSO, objFile Dim strTxt , strTxt1 , strpath strPath = "c:\text.txt" strTxt1 = "John" Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strPath, ForReading) While Not objFile.AtEndOfStream strTxt = objFile.Readline If Instr(strTxt,strTxt1) > 0 Then MsgBox "I Found John" Else MsgBox "John Not found" End If Next
This will search each line of a file and tell you if John exists
Option Explicit Dim objFSO, objFile Dim strTxt , strTxt1 , strpath strPath = "c:\text.txt" strTxt1 = "John" Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strPath, ForReading) strTxt = objFile.Readall If Instr(strTxt,strTxt1) > 0 Then MsgBox "I Found John" Else MsgBox "John Not found" End If
This will read file and then check to see if John exists.
< Message edited by
chiltz
--
8/14/2008 5:53:23 AM
>
(in reply to
dm_4ever
)
Post #: 3
If you found our site useful please link to us
<a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>
.
All Forums
>>
[Scripting]
>>
WSH & Client Side VBScript
>> How to search for a string in a text
Page:
[1]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
New Messages
No New Messages
Hot Topic w/ New Messages
Hot Topic w/o New Messages
Locked w/ New Messages
Locked w/o New Messages
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI