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 

I have lost my mind: stringtrimleft/right not working

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



Joined: 14 Feb 2007
Posts: 307

PostPosted: Tue Dec 15, 2009 11:52 pm    Post subject: I have lost my mind: stringtrimleft/right not working Reply with quote

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

Back to top
View user's profile Send private message
Guest






PostPosted: Wed Dec 16, 2009 1:19 am    Post subject: Reply with quote

?
Code:
temphtml = 123456789abcdef
stringgetpos,posend,temphtml,b,L1
StringLeft,temphtml2,temphtml,%posend%

msgbox, firstchop at %posend% %temphtml2%
clipboard = firstchop at %posend% %temphtml2%
exitapp
Back to top
degarb



Joined: 14 Feb 2007
Posts: 307

PostPosted: Thu Dec 17, 2009 12:16 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Thu Dec 17, 2009 1:41 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
degarb



Joined: 14 Feb 2007
Posts: 307

PostPosted: Thu Dec 17, 2009 3:03 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Thu Dec 17, 2009 5:48 am    Post subject: Reply with quote

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.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
hd0202



Joined: 13 Aug 2006
Posts: 265
Location: Germany

PostPosted: Thu Dec 17, 2009 6:20 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
degarb



Joined: 14 Feb 2007
Posts: 307

PostPosted: Thu Dec 17, 2009 2:06 pm    Post subject: Reply with quote

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 ?
Back to top
View user's profile Send private message
Display posts from previous:   
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