Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

detection chaine in other chaine

1 view
Skip to first unread message

karamel

unread,
Nov 3, 2009, 1:36:41 PM11/3/09
to
Hello

why i do for detect one string in a other string

example
j want find "toto" in an other string
if is good i do then
if is not good else

instr ? but i have bad response and it's no good

help please
thank


Pegasus [MVP]

unread,
Nov 3, 2009, 1:42:46 PM11/3/09
to

"karamel" <kar...@yahoo.fr> wrote in message
news:4af0783c$0$907$ba4a...@news.orange.fr...

What you call a "chain" is called a "string" in English. I recommend that
you download the helpfile script56.chm from the Microsoft site. It gives you
a detailed explanation of the "instr" function, including a specific
example. If this does not suffice then you should post the code that does
not work for you.


Hz

unread,
Nov 3, 2009, 3:40:37 PM11/3/09
to

Here's a simple example I threw together, how to use regular expressions
to find all occurrences of a string inside another string:

'###########################################
Set find = CreateObject("VBScript.RegExp")
With find
.Global = True
.IgnoreCase = True
.Pattern = "toto"
End With
testData = "-toto-Toto-tOto-toTo-totO-TOTO-"
Set finds = Find.Execute(testData)
For Each pos in finds
WScript.Echo pos.Value & " " & pos.FirstIndex
Next
Set finds = Nothing
Set find = Nothing
'###########################################

Output:

toto 1
Toto 6
tOto 11
toTo 16
totO 21
TOTO 26

--
.::[ Hz ]::.

Al Dunbar

unread,
Nov 4, 2009, 12:08:15 AM11/4/09
to

"Pegasus [MVP]" <ne...@microsoft.com> wrote in message
news:eI6HpVLX...@TK2MSFTNGP04.phx.gbl...

Another useful bit of advise to the OP would be to suggest he include a copy
of the script that is giving a "bad response" so we would have a hope in
heck of being able to point out where he might have gone wrong.

/Al

Pegasus [MVP]

unread,
Nov 4, 2009, 2:11:22 AM11/4/09
to

"Al Dunbar" <alan...@hotmail.com> wrote in message
news:OiA%23QzQXK...@TK2MSFTNGP02.phx.gbl...

Mmh. Isn't this what I suggested in my last sentence?


karamel

unread,
Nov 4, 2009, 12:11:19 PM11/4/09
to
my script (bad, and j don't understand)
fullname is a fic name
______________________________________________________
set fso_sansaccent_exeptions = fso.OpenTextFile(fichier_exeptions)
while Not fso_sansaccent_exeptions.AtEndOfStream
exeption = fso_sansaccent_exeptions.ReadLine

if instr(fullname, exeption) <> 0 then
wscript.echo fullname & " : EXEPTION, pas de traitement !!!!!!!!!"
else
wscript.echo fullname & " : traitement !!!!!!!!!"

end if

wend
________________________________________________________


thank you very much

"Hz" <h...@trashymail.com> a �crit dans le message de news:
%23BHOkXM...@TK2MSFTNGP04.phx.gbl...

Pegasus [MVP]

unread,
Nov 4, 2009, 1:02:50 PM11/4/09
to

"karamel" <kar...@yahoo.fr> wrote in message
news:4af1b5b6$0$965$ba4a...@news.orange.fr...

> my script (bad, and j don't understand)
> fullname is a fic name
> ______________________________________________________
> set fso_sansaccent_exeptions = fso.OpenTextFile(fichier_exeptions)
> while Not fso_sansaccent_exeptions.AtEndOfStream
> exeption = fso_sansaccent_exeptions.ReadLine
>
> if instr(fullname, exeption) <> 0 then
> wscript.echo fullname & " : EXEPTION, pas de traitement !!!!!!!!!"
> else
> wscript.echo fullname & " : traitement !!!!!!!!!"
>
> end if
>
> wend
> ________________________________________________________
>
>
> thank you very much
>

I can't entirely follow the logic in your script but I note two problems:
- You reversed the position of the two arguments in your "instr"-function.
- You performed a binary rather than an ASCII comparison.
Try this modified script:

fichier_exeptions = "d:\test.txt"
sFullName = "c:\boot.ini"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set ofso_sansaccent_exeptions = oFSO.OpenTextFile(fichier_exeptions)
While Not ofso_sansaccent_exeptions.AtEndOfStream
sLine = ofso_sansaccent_exeptions.ReadLine
If InStr(1, sLine, sFullName, 1) > 0 Then
WScript.echo sLine & " : EXEPTION, pas de traitement !!!!!!!!!"
Else
WScript.echo sLine & " : traitement !!!!!!!!!"
End If
Wend


Al Dunbar

unread,
Nov 8, 2009, 8:36:18 PM11/8/09
to

"Pegasus [MVP]" <ne...@microsoft.com> wrote in message
news:evjk83RX...@TK2MSFTNGP05.phx.gbl...

Memo to self: try to remember to read more closely before responding. My
apologies.

/Al

karamel

unread,
Nov 9, 2009, 1:38:37 PM11/9/09
to
it's good thank you
bye

"Pegasus [MVP]" <ne...@microsoft.com> a �crit dans le message de news:
uSNv%23jXXK...@TK2MSFTNGP06.phx.gbl...

Pegasus [MVP]

unread,
Nov 9, 2009, 1:42:24 PM11/9/09
to

"karamel" <kar...@yahoo.fr> wrote in message
news:4af861ad$0$968$ba4a...@news.orange.fr...

> it's good thank you
> bye

Thanks for the feedback.


0 new messages