hi,
i've created a script for count some type of characters into text file:

-----------------------
Const ForReading =3D 1
filename =3D "c:\test.txt"

Set objFSo =3D CreateObject("Scripting.FileSystemObject")
Set objFile =3D objFSO.OpenTextFile(filename, ForReading)

strFindText =3D "=EC"

Do While objFile.AtEndOfStream =3D False
strLine =3D objFile.ReadLine
If inStr(strLine, strFindText) Then
i =3D i + 1
End If
Loop

Wscript.Echo vbCrLf & "Number of records =EC found: " & i
objFile.Close
-------------------------

But this script search all the first char on each line, but i want to
count all chars in all line not only the first.

Someone can help me?

thanks very much
andrew

Re: script for count some char in a file by McKirahan

McKirahan
Wed Jan 24 06:11:14 CST 2007

"Andrea" <netsecurity@tiscali.it> wrote in message
news:1169638163.273973.197700@m58g2000cwm.googlegroups.com...
hi,
i've created a script for count some type of characters into text file:

[snip]

But this script search all the first char on each line, but i want to
count all chars in all line not only the first.

Someone can help me?

You can adapt this script to your needs.

The "identifies and counts characters in a file". Change the
value of "cTXT" to the full path and filename of your file.

Change the value of "cBYT" to "False: and it will identify
"only unprintable characters".

If "cBYT = True" then run it via CSCRIPT
and pipe the output to a file; for example,
>cscript //nologo Chr.vbs > Chr.log


Option Explicit
'****
'* "Chr_.vbs" -- identifies and counts characters in a file.
'****
'*
'* Declare Constants
'*
Const cVBS = "Chr.vbs"
Const cLOG = "Chr.log"
Const cTXT = "c:\test.txt"
Const cBYT = True '= False (only unprintable characters)
'*
'* Declare Variables
'*
Dim arrBYT(255)
Dim booBYT
Dim intBYT
For intBYT = 0 To UBound(arrBYT)
arrBYT(intBYT) = 0
Next
Dim strBYT
Dim arrOTF
Dim intOTF
Dim strOTF
Dim strSFN
strSFN = WScript.ScriptFullName
strSFN = Left(strSFN,InStrRev(strSFN,"\"))
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
Set objOTF = objFSO.OpenTextFile(cTXT,1)
strOTF = objOTF.ReadAll()
Dim objCTF
Set objCTF = objFSO.CreateTextFile(strSFN & cLOG,True)
'*
'* Process
'*
arrOTF = Split(strOTF,vbCrLf)
For intOTF = 0 To UBound(arrOTF,1)
strOTF = arrOTF(intOTF)
For intBYT = 1 To Len(strOTF)
strBYT = Mid(strOTF,intBYT,1)
arrBYT(Asc(strBYT)) = arrBYT(Asc(strBYT)) + 1
Next
Next
'*
strBYT = ""
For intBYT = 0 To UBound(arrBYT)
booBYT = True
If Not cBYT And (intBYT >= 32 Or intBYT <= 126) Then
booBYT = False
End If
If booBYT Then
If arrBYT(intBYT) > 0 Then
strBYT = strBYT & vbCrLf & intBYT & " = " _
& Chr(intBYT) & " = " & arrBYT(intBYT)
End If
End If
Next
'*
objCTF.Write strBYT
'*
'* Destroy Objects
'*
Set objCTF = Nothing
Set objOTF = Nothing
Set objFSO = Nothing
'*
MsgBox "Done!",vbInformation,cVBS



Re: script for count some char in a file by McKirahan

McKirahan
Wed Jan 24 06:14:40 CST 2007

"McKirahan" <News@McKirahan.com> wrote in message
news:ou6dnVUDdbV_0SrYnZ2dnUVZ_vOlnZ2d@comcast.com...
> "Andrea" <netsecurity@tiscali.it> wrote in message
> news:1169638163.273973.197700@m58g2000cwm.googlegroups.com...
> hi,
> i've created a script for count some type of characters into text file:
>
> [snip]

>
> If "cBYT = True" then run it via CSCRIPT
> and pipe the output to a file; for example,
> >cscript //nologo Chr.vbs > Chr.log

Forget the above as I modified the script to
send the output to the log file (i.e. "cLOG)".


Also,
The "identifies and counts characters in a file".
should have been
This "identifies and counts characters in a file".

And,
Change the value of "cBYT" to "False:
should have been
Change the value of "cBYT" to "False"



Re: script for count some char in a file by Anthony

Anthony
Wed Jan 24 06:49:08 CST 2007

>>>
"Andrea" <netsecurity@tiscali.it> wrote in message
news:1169638163.273973.197700@m58g2000cwm.googlegroups.com...
hi,
i've created a script for count some type of characters into text file:

-----------------------
Const ForReading = 1
filename = "c:\test.txt"

Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(filename, ForReading)

strFindText = "ì"

Do While objFile.AtEndOfStream = False
strLine = objFile.ReadLine
If inStr(strLine, strFindText) Then
i = i + 1
End If
Loop

Wscript.Echo vbCrLf & "Number of records ì found: " & i
objFile.Close
-------------------------

But this script search all the first char on each line, but i want to
count all chars in all line not only the first.

Someone can help me?

thanks very much
andrew
<<<

cnt = Len(s) - Len(Replace(s, c, ""))

Where c contains the character you are looking for.

Also consider using ReadAll instead of ReadLine so you can eliminate the
loop



Re: script for count some char in a file by Andrea

Andrea
Wed Jan 24 07:06:50 CST 2007

On 24 Gen, 13:17, "McKirahan" <N...@McKirahan.com> wrote:
> "McKirahan" <N...@McKirahan.com> wrote in

> > If "cBYT = True" then run it via CSCRIPT
> > and pipe the output to a file; for example,
> > >cscript //nologo Chr.vbs > Chr.logForget the above as I modified the script to
> send the output to the log file (i.e. "cLOG)".
>
> Also,
> The "identifies and counts characters in a file".
> should have been
> This "identifies and counts characters in a file".
>
> And,
> Change the value of "cBYT" to "False:
> should have been
> Change the value of "cBYT" to "False"


thanks for the script!
But if i want to count only one specified character? how i modify this
script? :(

thanks
bye


Re: script for count some char in a file by LJB

LJB
Wed Jan 24 08:28:33 CST 2007


"Andrea" <netsecurity@tiscali.it> wrote in message
news:1169638163.273973.197700@m58g2000cwm.googlegroups.com...
hi,

(snip)

But this script search all the first char on each line, but i want to
count all chars in all line not only the first.

Someone can help me?

thanks very much
andrew
--------------------------------------

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



Re: script for count some char in a file by E

E
Wed Jan 24 08:44:42 CST 2007

check out the below, regexp will return the number of matches for your
search. Also, you can read the whole file, and search that way.

http://www.regular-expressions.info/vbscript.html

Andrea wrote:
> hi,
> i've created a script for count some type of characters into text file:
>
> -----------------------
> Const ForReading = 1
> filename = "c:\test.txt"
>
> Set objFSo = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile(filename, ForReading)
>
> strFindText = "ì"
>
> Do While objFile.AtEndOfStream = False
> strLine = objFile.ReadLine
> If inStr(strLine, strFindText) Then
> i = i + 1
> End If
> Loop
>
> Wscript.Echo vbCrLf & "Number of records ì found: " & i
> objFile.Close
> -------------------------
>
> But this script search all the first char on each line, but i want to
> count all chars in all line not only the first.
>
> Someone can help me?
>
> thanks very much
> andrew
>

Re: script for count some char in a file by Andrea

Andrea
Thu Jan 25 02:57:38 CST 2007

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


Re: script for count some char in a file by LJB

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"))



Re: script for count some char in a file by Andrea

Andrea
Mon Jan 29 03:59:11 CST 2007

On 24 Gen, 15:28, "LJB" <.> wrote:
> mychar =3D "A"
>
> mytext =3D CreateObject("Scripting.FileSystemObject") _
> .OpenTextFile("C:\test.txt", 1) _
> .ReadAll
>
> set re =3D CreateObject("VBScript.RegExp")
> re.IgnoreCase =3D false
> re.Global =3D true
> re.multiline =3D true
> re.pattern =3D "[" & mychar & "]"
>
> count =3D re.execute(mytext).count
>
> wscript.echo mychar & " found " & count

this source code work, thanks. But it doesn't replace upcase=20
characters (es. =D9)
why??

thanks


Re: script for count some char in a file by LJB

LJB
Mon Jan 29 10:36:34 CST 2007


"Andrea" <netsecurity@tiscali.it> wrote in message
news:1170064751.258294.173000@j27g2000cwj.googlegroups.com...
On 24 Gen, 15:28, "LJB" <.> wrote:
> 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

this source code work, thanks. But it doesn't replace upcase
characters (es. Ù)
why??

thanks

I copied the following from the vbscript 5.6 help file. Perhaps \xD9 would
match Ù.

\xn
where n is a hexadecimal escape value. Hexadecimal escape values must be
exactly two digits long. For example, "\x41" matches "A". "\x041" is
equivalent to "\x04" & "1". Allows ASCII codes to be used in regular
expressions.