AutoHotkey Community

It is currently May 26th, 2012, 4:16 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: StrGet (And StrPut)
PostPosted: April 15th, 2009, 4:13 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
It would be nice to have functions like NumGet and NumPut only for strings/raw data.

So basically StrGet would be like SubStr, except it would tolerate NULs in the string.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 5:28 am 
Offline

Joined: June 26th, 2008, 3:58 am
Posts: 56
You can't have nulls in a string because strings are null-terminated. Meaning that if there is a null in the middle of a string, ahk will only see the first half because it thinks that the null marks the end of the string.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 8:11 am 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
It is possible to work with NUL in AutoHotkey. In example with NumGet, which just read one cell from the RAM. It does not matter what data is in here.
Normally, you are right. Ahk just see the first NUL and stops. NUL could be used to safely and fast delimit a list in a standardized way in example.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 1:48 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
What is the proposed behaviour of StrGet? All strings in expressions are null-terminated, so the return value of StrGet and incoming parameters of StrPut could not contain NULL characters. (Variable references are an exception since each variable has an internal field which stores the length of its contents.)

I think the use of "Str" in the name of the function implies it works with strings, not necessarily binary data, and "StrGet" does not imply a difference in behaviour to "SubStr".

Perhaps the best solution would be to implement counted strings, allowing explicit null characters (or "zero bytes"). In cases where the length of the string would otherwise need to be calculated, this can also improve performance. Unfortunately it is not a simple matter.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2009, 12:37 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
I suggested him to post in Wish List section from here.
http://www.autohotkey.com/forum/topic43222.html

I think StrLen should be to accord with the current behavior
Code:
StrLen("ansi-string", "U(nicode)/A(nsi)")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 6th, 2009, 10:23 pm 
Code:
    textThe:="hello world"   
    msgbox % StrGet(&textThe)
ExitApp

StrGet(address)
{
    i=0
    Loop
    {
        char := NumGet(address + 0, i, "UChar")
        if !char
            Break
        out .= Chr(char)
        i++   
    }
    Return out
}


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: gamax92 and 1 guest


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