Results 1 to 22 of 22

Thread: string limit

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    string limit

    how much text can I put into a string variable

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    something like 2 billion chars, or when you run out of memory, whichever happens sooner.

  3. #3
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    4 GB for a variable-length string
    64k for fixed-length string

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    That should just about do it!

    Thanks guys.

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    I think you cant reach the 4 GB only if you have close to 4 gb ram.

  6. #6
    Some functions are freaky. Mid only does strings that have 65,535 (unsigned int) chars at most.

  7. #7
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    Not true try this
    VB Code:
    1. ss = String(70000, "l") & "this is more than 69000 spaces Hello"
    2. ss = Mid(ss, 69000)
    3. MsgBox ss
    It works

  8. #8
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    Vb / Reference / Additional Info / Data Type Summary
    String
    (variable-length) 10 bytes + string length 0 to approximately 2 billion

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Nucleus
    4 GB for a variable-length string
    64k for fixed-length string
    It's actually 2 GB for variable-length strings. Every process in Windows gets a virtual memory space of 4 GB but 2 of them is reserved for Windows itself. So that leaves you with 2 GB of space.
    But then again you can't have any other code besides the string in that case. But who cares the strings can be huge anyway.

  10. #10
    Dreamlax
    Guest
    2GB is also the file size limit on Win95 or 98, so maybe if you have a better file system, string lengths could be bigger...
    I have absolutely no idea, but it seems logical.

    I think the exact number of characters a string can have is:
    2 ^ 31 = 2,147,483,648

  11. #11
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    Th formulla is 10 + string Length 0 to 2 billion BUT number of bytes in string is 2 * string length (2 bytes Unicode per character). 2 Gig characters = 4 Gig bytes?

  12. #12
    Originally posted by shragel
    Not true try this
    VB Code:
    1. ss = String(70000, "l") & "this is more than 69000 spaces Hello"
    2. ss = Mid(ss, 69000)
    3. MsgBox ss
    It works
    Sorry, I mean InStr.

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by John Yingling
    Th formulla is 10 + string Length 0 to 2 billion BUT number of bytes in string is 2 * string length (2 bytes Unicode per character). 2 Gig characters = 4 Gig bytes?
    That is 0 to 2 billion bytes not characters.

  14. #14
    So up to 1 billion chars.

  15. #15
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    In VB help under the String Data Type is says that the max length is 2^31 chars, unless you run out of memory first. Another way of remembering that would be to remember that strings can hold the maximum number of a Long variable plus 1.
    You just proved that sig advertisements work.

  16. #16
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    originally posted by shragel
    Not true try this

    VB Code:
    1. ss = String(70000, "l") & "this is more than 69000 spaces Hello"
    2. ss = Mid(ss, 69000)
    3. MsgBox ss

    It works
    Sorry, I mean InStr.
    This also works

    VB Code:
    1. ss = String(70000, "l") & "this is more than 69000 spaces Hello"
    2. ss = InStr(ss, "t")
    3. MsgBox ss

  17. #17
    wossname
    Guest
    From the MSDN CD:
    '###########################

    String Data Type


    There are two kinds of strings: variable-length and fixed-length strings.

    A variable-length string can contain up to approximately 2 billion (2^31) characters.


    A fixed-length string can contain 1 to approximately 64K (2^16) characters.
    Note APublic fixed-length string can't be used in aclass module.

    The codes forString characters range from 0–255. The first 128 characters (0–127) of the character set correspond to the letters and symbols on a standard U.S. keyboard. These first 128 characters are the same as those defined by theASCII character set. The second 128 characters (128–255) represent special characters, such as letters in international alphabets, accents, currency symbols, and fractions. Thetype-declaration character for String is the dollar sign ($).

  18. #18
    Originally posted by shragel
    VB Code:
    1. ss = String(70000, "l") & "this is more than 69000 spaces Hello"
    2. ss = InStr(ss, "t")
    3. MsgBox ss
    Arg, I know some string function fails because MS wrote it using unsigned int as an index pointer. I thought it was InStr or Mid, but know, who knows?

  19. #19
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by John Yingling
    Th formulla is 10 + string Length 0 to 2 billion BUT number of bytes in string is 2 * string length (2 bytes Unicode per character). 2 Gig characters = 4 Gig bytes?
    That is correct. A variable length string can take up to 4GB+10 bytes, a byte string could obtain 2^32 characters.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  20. #20
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    Is there anyone who has a problem with the limit.
    If not whats the difference of the exact limit??

  21. #21
    Dreamlax
    Guest
    So if your string contained just characters 0 through 255, is it possible to remove the second byte and save memory by removing all null values?

    ie
    T_E_S_T_

    where the underscores are chr(0)s (or do they go first?!?). Couldn't you then remove the chr(0)s and have

    TEST

    and save it into memory as 'Unicode' but not. Who knows what I mean?
    ??????

  22. #22
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by Dreamlax
    So if your string contained just characters 0 through 255, is it possible to remove the second byte and save memory by removing all null values?

    ie
    T_E_S_T_

    where the underscores are chr(0)s (or do they go first?!?). Couldn't you then remove the chr(0)s and have

    TEST

    and save it into memory as 'Unicode' but not. Who knows what I mean?
    ??????
    Most of the time, you shold stay to unicode, since everything that is displayed as text is interpreted as unicode. Anyway, if you want to store large amount of characters 0 trough 255 you can use Strconv(stringname,vbfromUnicode) to return a byte array instead. And to convert back you can use Strconv(stringname,vbUnicode)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width