LJB
Thu Jan 25 07:08:27 CST 2007
"Andrea" <netsecurity@tiscali.it> wrote in message
news:1169715458.515967.57310@v45g2000cwv.googlegroups.com...
> On 24 Gen, 15:28, "LJB" <.> wrote:
>> --------------------------------------
>>
>> Using Regular Expressions it could be done as follows. I have it set to
>> case
>> sensitive but that can be changed.
>>
>> mychar = "A"
>>
>> mytext = CreateObject("Scripting.FileSystemObject") _
>> .OpenTextFile("C:\test.txt", 1) _
>> .ReadAll
>>
>> set re = CreateObject("VBScript.RegExp")
>> re.IgnoreCase = false
>> re.Global = true
>> re.multiline = true
>> re.pattern = "[" & mychar & "]"
>>
>> count = re.execute(mytext).count
>>
>> wscript.echo mychar & " found " & count
>
> perfect! thanks, i improve my script (find and replace chars) with your
> code :)
> So, if i would to know on wich rows (number of line) there are this
> characters??
>
> thanks
>
Use a variation of the code below found at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/711116fb-9c47-47cb-b664-db8141b8cc69.asp
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search.
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))