Sign in to follow this  
Followers 0
ArviUTA

String Comparison of Strings stored in arrays

11 posts in this topic

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

Share this post


Link to post
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

Share this post


Link to post
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 "

Share this post


Link to post
Share on other sites

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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))
still no use

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I Used StringSplit function to split the string and then inserted them again using _StringInsert function to get those blank spaces out. It was cumersome but it worked out thank you guys for your help

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