Jump to content

String Comparison of Strings stored in arrays


Recommended Posts

Hi Guys,

I have two arrays

$array1 and $array2 which contains strings taken from seperate columns from excel sheets. I wasn't able to compare these strings. i used both StringCompare but they turned out to be negative even if the words are same. I even used StringStripWS to take away the white spaces . It was of no use, please give me some ideas.

thanks

Arvinth

Link to comment
Share on other sites

Show some code/snippet how you are doing the compare and what the content of the arrays is.

Jos

********************88getting values from excel in array *******************************************88

for $j = 1 To ($row - 1)

$marry=_ExcelReadCell($oWorkbook,$j)

_arrayinsert($array,$j-1,$marry)

$array[$j-1] = StringTrimRight($array[$j-1], 1)

Next

****************************8getting values for another array *******************************************

### Since the column have interleaved spaces i have few extra conditions

func arjun($obook)

$r=3

while 1

$rowvar = _ExcelReadCell($obook,$r,4)

;MsgBox(0,"Values",$rowvar)

if $rowvar = "" then

$r+=1

;MsgBox(0,"Values","i am here")

$n+=1

if $n > 1 then

ExitLoop

EndIf

Else

;MsgBox(0,"Values",$rowvar)

;MsgBox(0,"Vale of m",$m)

_arrayinsert($array1,$m,$rowvar)

$r+=1

$m+=1

;ConsoleWrite($array1[$m])

$n=0

Endif

WEnd

for $k=0 to ($m)

ConsoleWrite($array1[$k])

Next

EndFunc

****************************************************************************************************

**********************************

Both arrays have required information, but the array has the strings stored without any gap, whereas above one have one white space before and after the word

i even used StringStripWS to strip the second array ie array1 just above this. but ultimately the space remain in array1.

****************************************************************************************************

**********************************

************** for matching ************************************************

for $j=0 to ($row-2)

for $k=0 to $m

if ($array[$j] == $array1[$k]) Then

_ArrayAdd($array2,$array1[$k])

EndIf

Next

Next

******************************************************************************8

i may not be clear just replay me if you are not clear

Link to comment
Share on other sites

  • Developers

Have you listed the exact content of both arrays to see what they contain and why there is no match ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Have you listed the exact content of both arrays to see what they contain and why there is no match ?

yes i console wrote them and

for example if

array1 contains an element "ssssssssss545454"

array2 contains same element " sssssssssssss545454 "

Link to comment
Share on other sites

  • Developers

Do you mean that the s'es are spaces?

If so, you could strip all spaces when adding the cell content eg:

_arrayinsert($array1,$m,StringStripWS($rowvar,3))

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

still no use

Build and snippet that we can run containing some actual array values that do not work, else its difficult to help you as it will only be guessing.

Jos :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

yes i console wrote them and

for example if

array1 contains an element "ssssssssss545454"

array2 contains same element " sssssssssssss545454 "

array1 contains an element...... "ssssssssss545454"

array2 contains same element " sssssssssssss545454 "

You mentioned array2 contains the same element.

If you compare the above 2 strings they are not the same. Too many s's in array2.

Link to comment
Share on other sites

  • 2 weeks later...

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...