AutoHotkey Community

It is currently May 27th, 2012, 12:36 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: December 16th, 2009, 12:52 am 
Offline

Joined: February 14th, 2007, 8:01 pm
Posts: 308
I cant get the stringtrim to work tonight. All I want to do find </a and chop off everything to right of beginning position of it. the behavior makes no logical sense.

result is firstchop at 10 bcdef

while expected result is: Firstchop at 10 is 123456789a

which makes no sense. What is wrong?

Code:
temphtml = 123456789abcdef
stringgetpos,posend,temphtml,b,L1
stringtrimleft,temphtml2,temphtml,%posend%
msgbox, firstchop at %posend% %temphtml2%
clipboard = firstchop at %posend% %temphtml2%
exitapp



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2009, 2:19 am 
?
Code:
temphtml = 123456789abcdef
stringgetpos,posend,temphtml,b,L1
StringLeft,temphtml2,temphtml,%posend%

msgbox, firstchop at %posend% %temphtml2%
clipboard = firstchop at %posend% %temphtml2%
exitapp


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 1:16 am 
Offline

Joined: February 14th, 2007, 8:01 pm
Posts: 308
Thanks. It was a late night and I finally figured it out that I needed stringleft.

I left the post up, since I think the reason for my confusion is the behavior isn't how I think it should be. And so, I am having trouble understanding stringleft , and hoping for someone to fix it in my dense mind.

To me, a proper design is stringleft, var, var, %position number from left% = trim everything to left of "PNFL%
And, stringright, var, var, %position number from left% = trim everything to Right of "PNFL%

Except it appears on string right it starts counting from right. WTF? (What the Function?)

If anyone has the way to remember this, I am all eyes. After a few hours wrestling before getting the clipping to work, and not exactly understanding what I did to get it to work, I am emotionally, as yet, to play around with it to get it to work the way I think it should work.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 2:41 am 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
degarb wrote:

To me, a proper design is stringleft, var, var, %position number from left% = trim everything to left of "PNFL%
And, stringright, var, var, %position number from left% = trim everything to Right of "PNFL%

Except it appears on string right it starts counting from right. WTF? (What the Function?)


StringRight counts from the right side of the string to the left, stringleft the reverse.

StringLeft and StringRight both count a number of characters OUT from the character that you specify, in the only direction they can go.

In the above sentence, StringRight, OutputVar, InputVar, 5 would be: "n go."

If you want to pull data from the middle of a string, StringMid lets you specify a place to begin counting and the number to count off.

If you want to cut data from a string, see StringTrim in the help file.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 4:03 am 
Offline

Joined: February 14th, 2007, 8:01 pm
Posts: 308
I still don't get why this is designed so the position variable must be derived differently depending of if you want to clip right or left. Logically, the position number should always be from left, unless parametered otherwise.

Furthermore the docs on this are vague on how the count goes, other than the example.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 6:48 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
degarb wrote:
Logically, the position number should always be from left, unless parametered otherwise.


The whole point of StringLeft and StringRight is that you can extract a substring from the left or the right side of a string. To me there's no other logical way to designate how StringRight extracts a substring except counting right to left. If a string can be of a dynamic length but a substring you need from it is always the last three characters, then StringRight, Needle, Haystack, 3 makes perfect sense. The other substring/string position commands (StringMid, SubStr(), StringGetPos, InStr()) all work on a left-based count by default, although that can be changed per se for StringMid, SubStr() and StringGetPos.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 7:20 am 
Offline

Joined: August 13th, 2006, 6:45 am
Posts: 355
Location: Germany
degarb wrote:
... the position number should always be from left, unless parametered otherwise


Please have a look at the help file again, the parameter is named Count and not Position Number.

Hubert


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2009, 3:06 pm 
Offline

Joined: February 14th, 2007, 8:01 pm
Posts: 308
sinkfaze wrote:
degarb wrote:
Logically, the position number should always be from left, unless parametered otherwise.


The whole point of StringLeft and StringRight is that you can extract a substring from the left or the right side of a string. To me there's no other logical way to designate how StringRight extracts a substring except counting right to left. If a string can be of a dynamic length but a substring you need from it is always the last three characters, then StringRight, Needle, Haystack, 3 makes perfect sense. The other substring/string position commands (StringMid, SubStr(), StringGetPos, InStr()) all work on a left-based count by default, although that can be changed per se for StringMid, SubStr() and StringGetPos.


Good argument. I will try to think of it from this prospective, and I should never forget in future.

I get stringmid, very logical.

I don't get stringtrimleft and stringtrimright: what is the difference from stringleft; moreover, why are both functions (stl and sl) needed ?


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], iDrug, Leef_me, Ohnitiel, rjgatito, Yahoo [Bot] and 20 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