AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

string matching

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
esromneb



Joined: 06 Jan 2006
Posts: 53

PostPosted: Fri Jan 06, 2006 10:04 am    Post subject: string matching Reply with quote

I have 2 strings that I'm trying to match, they are both in an arrays. I know that the strings are the same becuase I'm getting them from the clip. I can't seem to get them to match however:

Quote:
....parse each line from the clip into the array....

MsgBox %TempLines4%%TempLines2% ; this shows test`ntest
if TempLines2 = TempLines4
{
msgbox YAY!
}


Quote:
Clipboard:
test
blas
test
asdfasdf


what the hell am I doing wrong.
Back to top
View user's profile Send private message
Rabiator



Joined: 17 Apr 2005
Posts: 265
Location: Sauerland

PostPosted: Fri Jan 06, 2006 10:54 am    Post subject: Reply with quote

Code:
if TempLines2 = %TempLines4%

See the example in the if section of the help file.
Back to top
View user's profile Send private message
esromneb



Joined: 06 Jan 2006
Posts: 53

PostPosted: Fri Jan 06, 2006 7:30 pm    Post subject: Reply with quote

Sweet that works, now why doesn't this work?

Code:
num := 4
if TempLines2 = TempLines%num%
{
msgbox YAY!
}
Back to top
View user's profile Send private message
Decarlo110



Joined: 15 Dec 2004
Posts: 303
Location: United States

PostPosted: Fri Jan 06, 2006 9:47 pm    Post subject: Reply with quote

Code:
num := 4
if TempLines2 = TempLines%num%

The above code will compare the variable TempLines2 with the string "TempLines4".

The following will compare variable TempLines2 with the variable TempLines4:
Code:
num := 4   ; removing the ":" in this case is equivalent
if ( TempLines2 = TempLines%num% )


This is a common question for those who have newly found AutoHotkey. I responded in a previous thread with tips that might help.
http://www.autohotkey.com/forum/viewtopic.php?t=4320
_________________
1) The Open Source Definition http://www.opensource.org/docs/definition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>>
Back to top
View user's profile Send private message
esromneb



Joined: 06 Jan 2006
Posts: 53

PostPosted: Sat Jan 07, 2006 3:27 am    Post subject: Reply with quote

Sorry for being such a noob, but I can't seem to get this working. I'm trying to cat the previously mentioned array into a string.

This works like it should, but it's not what I want:
Code:
dumpTemp = heya
Loop, 2
{
dumpTemp = %dumpTemp%%dumpTemp%
}
MsgBox, %dumpTemp%



And I can't get this to work at all:
Code:
dumpTemp =
Loop, 2
{
dumpTemp = %dumpTemp% Lines%A_Index%
}
MsgBox, %dumpTemp% ;shows "Lines1 Lines2"


Thanks so much!
Back to top
View user's profile Send private message
NiJo



Joined: 12 Nov 2005
Posts: 73

PostPosted: Sat Jan 07, 2006 4:39 am    Post subject: Reply with quote

Code:
dumpTemp =
Loop, 2
{
dumpTemp =% dumpTemp Lines%A_Index%
}
MsgBox, %dumpTemp%


I think you need to amke a few more experiments yourself to start understanding this...
Read the Variables and Expressions Topic from the Help File
Back to top
View user's profile Send private message
esromneb



Joined: 06 Jan 2006
Posts: 53

PostPosted: Sat Jan 07, 2006 5:31 am    Post subject: Reply with quote

I am trying everything I can, but the code you gave me doesn't work, I get a msgbox with the value of the 2nd index in the array, not the entire thing like it should. I read that portion of the help file, but I didn't see anything regarding what I need to do. Thanks!
Back to top
View user's profile Send private message
Rabiator



Joined: 17 Apr 2005
Posts: 265
Location: Sauerland

PostPosted: Sat Jan 07, 2006 6:47 am    Post subject: Reply with quote

esromneb wrote:
I am trying everything I can, but the code you gave me doesn't work, I get a msgbox with the value of the 2nd index in the array, not the entire thing like it should.

A suspicious hint! I think of two possibilities:
  1. The first variable of your array is empty.
  2. Maybe the first index of your array is 0? A Loop begins with index 1, so your first line has to be in Lines1.
Back to top
View user's profile Send private message
esromneb



Joined: 06 Jan 2006
Posts: 53

PostPosted: Sat Jan 07, 2006 10:20 am    Post subject: Reply with quote

I'm 99% sure that the first 4 (1-4) values of the array are filled.

here is my code that pulls those lines from the clip
Code:
text = %clipboard%
count := 4
Loop
{
  temp1 := InStr( text, "`n", 0 )
  if(temp1 == 0)
  {
    break
  }
  StringLeft, temp2, text, temp1
  Lines%count% := temp2
  count --
  temp3 := strlen(text) - temp1
  StringRight, text, text, temp3
}


I still can't get it to work!!! Sorry...
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Sat Jan 07, 2006 11:30 am    Post subject: Reply with quote

Please try this:
Code:
text = %clipboard%
i = 0
Loop, parse, text, `n
  {
     i++     
     Lines%i% := A_LoopField
  }

String =
Loop, %i%
  String := String .  Lines%A_Index% . "`n"

MsgBox, %String%
Does it produce the thing you want?
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
NiJo



Joined: 12 Nov 2005
Posts: 73

PostPosted: Sat Jan 07, 2006 2:43 pm    Post subject: Reply with quote

esromneb wrote:
I'm 99% sure that the first 4 (1-4) values of the array are filled.

The 1% is victory, because the first one will never be filled Confused.
With your script, the Lines1 will never be write, because in the loop 4, where it should make the Lines1, the instr($$$$) will give 0 and the loop will break before saving writing Lines1.
Just add a line, like this:

Code:
text = %clipboard%
count := 4
Loop
{
  temp1 := InStr( text, "`n", 0 )
  if(temp1 == 0)
  {
    Lines%count%:= text  ; Add this Line
    break
  }
  StringLeft, temp2, text, temp1
  Lines%count% := temp2
  count --
  temp3 := strlen(text) - temp1
  StringRight, text, text, temp3
}

And then you could use my other script, or just use the Toralf's one.
Back to top
View user's profile Send private message
esromneb



Joined: 06 Jan 2006
Posts: 53

PostPosted: Sun Jan 08, 2006 10:55 am    Post subject: Reply with quote

I got it to work. Thank all of you guys so much.

I used toralf's solution for my MsgBox, and my own code for constructing the string. Thanks all of you.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group