Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
compare 2 strings
#1
i created a ICsv object and have a multi line string from a clipboard that i want to remove duplicates. When i compare the strongs by len they match, vusally they match, bring in Excel they math BUT dont match in my QM macro... also if i copy the string into a seperate macro, they still dont match.... If i copy the 1st line and duplicate it, it still wont match!!

is there an issue with the ICsv & strings or getting string the clipboard?  even if you copy the text from my posting it still wont match... what am i doing wrong??
Code:
Copy      Help
str a= "The ITypeLib interface provides access to information about the type description in a type library."
str b= "The ITypeLib interface provides access to information about the type description in a type library."
str c= "The ITypeLib interface provides access to information about the type description in a type library."

out a=b
out a=a
#2
out a=b is not the way to compare strings
  best way is to use function
Code:
Copy      Help
StrCompare
 
Code:
Copy      Help
out StrCompare(a b)

for more info read here 
https://www.quickmacros.com/help/User/ID...StrCompare
or search the forum for StrCompare
#3
To compare str strings can be used a=b. out should be 1 if equal, else 0. But not lpstr strings.
#4
thanks. please copy my code above into your QM and try to do the string compare. either way it outputs 0, menaing none are equal even though they are the same

i am using the string from clipboard and placing it into a grid.... it constantly returns 0.  please read my first post
#5
Code:
Copy      Help
str a= "The ITypeLib interface provides access to information about the type description in a type library."
str b= "The ITypeLib interface provides access to information about the type description in a type library."
str c= "The ITypeLib interface provides access to information about the type description in a type library."

out a=b
out a=a
out StrCompare(a b)

output:
1
1
0
#6
thanks.  I get 3 0's in a row.  it comes from the clipboard(i use the getClip function).

if you notice your 3rd one is 0, but the comparision its identical to the 1st one. Which outputs 1.  why would they be different outputs... 

a=b and strCompare(a b) both should equal 1
#7
Lightbulb 
out StrCompare(a b) is 0 when the strings are the same. Are you by chance converting the string to a csv before comparing ?. If you are that would explain the 0 on a=b.
#8
When two strings seem equal but aren't, the reason may be:
- one of strings ends with newline or space and you don't see it.
- the strings have different newlines, for example \r\n and \n.
- one of strings has invisible characters.
- some characters that look the same actually have different Unicode codes.

To see all codes in a string, use function outb:
Code:
Copy      Help
str s="test"
outb s s.len 1


Forum Jump:


Users browsing this thread: 1 Guest(s)