AutoHotkey Community

It is currently May 27th, 2012, 6:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: string matching
PostPosted: January 6th, 2006, 10:04 am 
Offline

Joined: January 6th, 2006, 9:56 am
Posts: 50
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2006, 10:54 am 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
Code:
if TempLines2 = %TempLines4%

See the example in the if section of the help file.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2006, 7:30 pm 
Offline

Joined: January 6th, 2006, 9:56 am
Posts: 50
Sweet that works, now why doesn't this work?

Code:
num := 4
if TempLines2 = TempLines%num%
{
msgbox YAY!
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2006, 9:47 pm 
Offline

Joined: December 15th, 2004, 10:24 pm
Posts: 303
Location: United States
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>>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 3:27 am 
Offline

Joined: January 6th, 2006, 9:56 am
Posts: 50
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 4:39 am 
Offline

Joined: November 12th, 2005, 10:25 pm
Posts: 73
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 5:31 am 
Offline

Joined: January 6th, 2006, 9:56 am
Posts: 50
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 6:47 am 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 10:20 am 
Offline

Joined: January 6th, 2006, 9:56 am
Posts: 50
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 11:30 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2006, 2:43 pm 
Offline

Joined: November 12th, 2005, 10:25 pm
Posts: 73
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2006, 10:55 am 
Offline

Joined: January 6th, 2006, 9:56 am
Posts: 50
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, hd0202 and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group