Sign in to follow this  
Followers 0
NaPeK

How to count string in file

7 posts in this topic

Hi i need to count "<" and "/>" in xml file and check if they number is even number then show message box

how to do it ???

Share this post


Link to post
Share on other sites



Hi i need to count "<" and "/>" in xml file and check if they number is even number then show message box

how to do it ???

Check the help for examples of StringInStr() and/or StringRegExp() (the latter is harder to formulate, but if done, way cleaner and shorter). Both can give you the number of occurences of some string (only StringInStr() will require some looping).


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

tryed already with no results... thats why asking for help

Share this post


Link to post
Share on other sites

MyNameIs i tryed to fit your code here

Func Load()
    $Load = FileOpenDialog("Choose file" , @ScriptDir , "XML file (*.xml)")
    If @error Then
    MsgBox(4096,"","No file(s) choosed")
    Exit
    Else

; here code

    EndIf
EndFunc

but all the time it returns me values 1 and how to check if returned value is even number ?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

MyNameIs i tryed to fit your code here

Func Load()
    $Load = FileOpenDialog("Choose file" , @ScriptDir , "XML file (*.xml)")
    If @error Then
    MsgBox(4096,"","No file(s) choosed")
    Exit
    Else

; here code

    EndIf
EndFunc

but all the time it returns me values 1 and how to check if returned value is even number ?

do this:

Func Load()
$Load = FileOpenDialog("Choose file" , @ScriptDir , "XML file (*.xml)", 1)
If Not @error Then
$op = FileOpen($Load, 0)
$string = FileRead($op)
StringRegExpReplace($string, "\<", "")
$replaced1 = @extended
StringRegExpReplace($string, "\\>", "")
$replaced2 = @extended
MsgBox(0, 0, "There are " & $replaced1 & " < and" & $replaced2 & " /> in $string")
FileClose($op)
EndIf
EndFunc
Edited by Gif

Share this post


Link to post
Share on other sites

thx now workin ... :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0