Jump to content

StringInStr is not finding string containing a number


CreeTar
 Share

Recommended Posts

Hello there, since I am so confused, I wanna ask here if it's a fault on my side...

I check if a string contains "Internet Explorer 8", the string is from an UpdateCollection (IUpdate via ISearchResult via IUpdateSession...)

$test1 = StringInStr($IUpdate.Title, "Internet") ;returns 1
$test2 = StringInStr($IUpdate.Title, "Internet Explorer") ;returns 1
$test3 = StringInStr($IUpdate.Title, "Internet Explorer 8") ;returns 0!!! oO

If I fill $IUpdate.Title manually it works, if I use it filled by WindowsUpdateAgent it doesn't.

Then I made a test messagebox:

msgbox(0,"IE8","#" & $IUpdate.Title & "#" & @CRLF & "#Internet Explorer 8 für Windows XP#")

And it looks like this:

#Internet Explorer 8 für Windows XP#

#Internet Explorer 8 für Windows XP#

so filled manually or from WUA seem to have the same string.

I also tried

$ttest = String($IUpdate.Title)
$test1 = StringInStr($ttest, "Internet Explorer 8") ;returns still 0

I am sitting here now since like 20min. or so trying everything, reading help over and over...

Please help ^^

Link to comment
Share on other sites

So what does @Error return?

Remarks

The first character position is 1.

So if its geaving 0 there is probably something wrong (string dont contain a given substring)

Edit:

You can try to compare every char to see if its identical

something like this

#include <Array.au3>
$c = StringSplit("Internet Explorer 7","")
$a = StringSplit("Internet Explorer 8","")
Dim $b[$c[0]+1][2]
For $y = 1 To $c[0]
    $c[$y] = Asc($c[$y])
    $b[$y][1] = $c[$y]
    $a[$y] = Asc($a[$y])
    $b[$y][0] = $a[$y]
Next
For $r = 0 to UBound($b,1) - 1
    If $b[$r][0] <> $b[$r][1] Then MsgBox(0,$b[$r][0]&" diffrent from "&$b[$r][1]&" pos. "&$r,"'"&Chr($b[$r][0])&"' diffrent from "&"'"&Chr($b[$r][1])&"' on position "&$r)
Next

If it dont work than maby someone other can assist and help you better than i did :/

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Look at the hex version of your target string. It's possible that a non-conventional whitespace or non-normalized Unicode string is the cause of this. Only hex examination can tell.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

hehe, i used your script and it says:

31 different from 160 pos. 18

'' different from '' on position 18

So does it mean its ASCII 31 vs. ASCII 160? But 31 is underscore and i don't see the underscore,

i got a log file and it says:

2010-01-14 20:37:00 >> Checking available updates
2010-01-14 20:37:05 >> 1 updates found: Internet Explorer 8 für Windows XP
2010-01-14 20:37:07 >> Downloading 1 of 1 Internet Explorer 8 für Windows XP
2010-01-14 20:37:10 >> Installing 1 of 1 Internet Explorer 8 für Windows XP IE-Tags 1/2: 0/0
2010-01-14 20:37:24 >> Result for 1 of 1 Internet Explorer 8 für Windows XP: failed (Exception: 80240022)

So how can I avoid this, if I don't even "see" the difference? Is there a way to convert the string?

Edited by CreeTar
Link to comment
Share on other sites

probably the one way around it is to stringreplace($string,Chr(160),Chr(31)) "or replace($string,Chr(31),Chr(160))" and then test stringinstr

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

the one way around it is to stringreplace($string,Chr(160),Chr(31)) "or replace($string,Chr(31),Chr(160))" and then test stringinstr

Aww, I wanted to avoid such "hardcoded" solution, then i might try to remove simply all whitespaces including 31 and 160.

that way i should be safe without getting down to chars again.

Link to comment
Share on other sites

Well you can try it

In help file you have

ASCII Character (Codes)

under Appendix Reference and to replace anything that look like wihte space with "" nothing

There are probably better solutions like StringRegExp but i still did not learn how to use (one day i will that's for sure) it and i dono can it help you heare

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Aww, I wanted to avoid such "hardcoded" solution, then i might try to remove simply all whitespaces including 31 and 160.

that way i should be safe without getting down to chars again.

ASCII decimal 31 (0x1F) is US (Unit Separator) aka ^_ (Ctrl underscore, not underscore itself), while decimal 160 (0xA0) is a non-breakable whitespace.

Sounds like there is little consistency in ID strings returned by IE!

Those two non-conventional pseudo-whitespaces aren't even considered as whitespace by the classical tokens of regexp, including Posix.

You'd better then compare filtered versions after a regexp keeps only letters and digits. Not completely failproof, but who knows with special/control caracter IE string will contain in the next version/release/patch?

EDIT: sorry, I didn't notice you were rather new here!

So Welcome and here's what you can use:

$FilteredStr = StringRegExpReplace($Str, '[^a-zA-Z0-9]' '')

Litterally: replace any character of input string not an ASCII letter nor an ASCII digit by nothing.

Output will look a bit compact, but you just compare it, you don't read it after all.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

ASCII decimal 31 (0x1F) is US (Unit Separator) aka ^_ (Ctrl underscore, not underscore itself), while decimal 160 (0xA0) is a non-breakable whitespace.

Sounds like there is little consistency in ID strings returned by IE!

Those two non-conventional pseudo-whitespaces aren't even considered as whitespace by the classical tokens of regexp, including Posix.

You'd better then compare filtered versions after a regexp keeps only letters and digits. Not completely failproof, but who knows with special/control caracter IE string will contain in the next version/release/patch?

EDIT: sorry, I didn't notice you were rather new here!

So Welcome and here's what you can use:

$FilteredStr = StringRegExpReplace($Str, '[^a-zA-Z0-9]' '')

Litterally: replace any character of input string not an ASCII letter nor an ASCII digit by nothing.

Output will look a bit compact, but you just compare it, you don't read it after all.

Thanks for the example, I always struggle a bit with RegEx :D
Link to comment
Share on other sites

Thanks for the example, I always struggle a bit with RegEx :D

You lucky man. Regexp are cool friends compared with the dragon personified by my mate...

Any taker around?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...