| View previous topic :: View next topic |
| Author |
Message |
esromneb
Joined: 06 Jan 2006 Posts: 53
|
Posted: Fri Jan 06, 2006 10:04 am Post subject: string matching |
|
|
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 |
|
 |
Rabiator
Joined: 17 Apr 2005 Posts: 265 Location: Sauerland
|
Posted: Fri Jan 06, 2006 10:54 am Post subject: |
|
|
| Code: | | if TempLines2 = %TempLines4% |
See the example in the if section of the help file. |
|
| Back to top |
|
 |
esromneb
Joined: 06 Jan 2006 Posts: 53
|
Posted: Fri Jan 06, 2006 7:30 pm Post subject: |
|
|
Sweet that works, now why doesn't this work?
| Code: | num := 4
if TempLines2 = TempLines%num%
{
msgbox YAY!
} |
|
|
| Back to top |
|
 |
Decarlo110
Joined: 15 Dec 2004 Posts: 303 Location: United States
|
Posted: Fri Jan 06, 2006 9:47 pm Post subject: |
|
|
| 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 |
|
 |
esromneb
Joined: 06 Jan 2006 Posts: 53
|
Posted: Sat Jan 07, 2006 3:27 am Post subject: |
|
|
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 |
|
 |
NiJo
Joined: 12 Nov 2005 Posts: 73
|
Posted: Sat Jan 07, 2006 4:39 am Post subject: |
|
|
| 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 |
|
 |
esromneb
Joined: 06 Jan 2006 Posts: 53
|
Posted: Sat Jan 07, 2006 5:31 am Post subject: |
|
|
| 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 |
|
 |
Rabiator
Joined: 17 Apr 2005 Posts: 265 Location: Sauerland
|
Posted: Sat Jan 07, 2006 6:47 am Post subject: |
|
|
| 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:
- The first variable of your array is empty.
- 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 |
|
 |
esromneb
Joined: 06 Jan 2006 Posts: 53
|
Posted: Sat Jan 07, 2006 10:20 am Post subject: |
|
|
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 |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Sat Jan 07, 2006 11:30 am Post subject: |
|
|
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 |
|
 |
NiJo
Joined: 12 Nov 2005 Posts: 73
|
Posted: Sat Jan 07, 2006 2:43 pm Post subject: |
|
|
| 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 .
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 |
|
 |
esromneb
Joined: 06 Jan 2006 Posts: 53
|
Posted: Sun Jan 08, 2006 10:55 am Post subject: |
|
|
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 |
|
 |
|