how much text can I put into a string variable
Printable View
how much text can I put into a string variable
something like 2 billion chars, or when you run out of memory, whichever happens sooner.
4 GB for a variable-length string
64k for fixed-length string
That should just about do it!
Thanks guys.
I think you cant reach the 4 GB only if you have close to 4 gb ram.
Some functions are freaky. Mid only does strings that have 65,535 (unsigned int) chars at most.
Not true try this
It worksVB Code:
ss = String(70000, "l") & "this is more than 69000 spaces Hello" ss = Mid(ss, 69000) MsgBox ss
Vb / Reference / Additional Info / Data Type Summary
String
(variable-length) 10 bytes + string length 0 to approximately 2 billion
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.Quote:
Originally posted by Nucleus
4 GB for a variable-length string
64k for fixed-length string
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.
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
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?
Sorry, I mean InStr.Quote:
Originally posted by shragel
Not true try this
It worksVB Code:
ss = String(70000, "l") & "this is more than 69000 spaces Hello" ss = Mid(ss, 69000) MsgBox ss
That is 0 to 2 billion bytes not characters.Quote:
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?
So up to 1 billion chars.
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.
This also worksQuote:
Sorry, I mean InStr.Quote:
originally posted by shragel
Not true try this
VB Code:
ss = String(70000, "l") & "this is more than 69000 spaces Hello" ss = Mid(ss, 69000) MsgBox ss
It works
VB Code:
ss = String(70000, "l") & "this is more than 69000 spaces Hello" ss = InStr(ss, "t") MsgBox ss
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 ($).
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? :(Quote:
Originally posted by shragel
VB Code:
ss = String(70000, "l") & "this is more than 69000 spaces Hello" ss = InStr(ss, "t") MsgBox ss
That is correct. A variable length string can take up to 4GB+10 bytes, a byte string could obtain 2^32 characters.Quote:
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?
Is there anyone who has a problem with the limit.
If not whats the difference of the exact limit??
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?
???:confused::confused::confused:???
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)Quote:
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?
???:confused::confused::confused:???